php - How to json_encode on json data that has single-quote? -


after fetching db, perform print json_encode on below

function queryprintjson($cnx, $query) {     $rows=queryreturnjsonarray($cnx, $query);            print json_encode($rows, json_hex_apos); }  function queryreturnjsonarray($cnx, $query) {     $result=mysqli_query($cnx, $query) or die ("can't execute query!");     $rows = array();      while($obj = $result->fetch_object()){         $rows[] = $obj;     }     $result->close();     return $rows; } 

it doesn't print anything. after debugging i.e. var_dump etc, simplify query, reducing data result... can't realize because 1 of field (description) contain single quote (i.e. ') in it. existence of single quote, can't json_encode working.

is there anyway work around this, go database , manually edit data escape character? perhaps way replace auto-escape single-quote after got retrieve db?

updated apparently not due single quote issue, special single quote call right single quote mark. check http://unicodelookup.com/#’'/1

found 1 , – , -. refer http://unicodelookup.com/#–-/1. first 1 cause json_encode not return anything.

another 1 “ , ". http://unicodelookup.com/#“"/1

single quote shouldn't affect json_encode() function.

example.

$person = array(     "name" => "i don't know name",     "email" => "i don't know email well" );    print_r($person); 

output

array (     [name] => don't know name     [email] => don't know email ) 

and

echo json_encode($person); 

output

{"name":"i don't know name","email":"i don't know email well"} 

Comments