After fetching from the DB, I perform a print json_encode on it as 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 the query, reducing the data result... I can't to realize this is because one of the field (description) contain single quote (i.e. ') in it. With the existence of this single quote, I can't get my json_encode
working.
Is there anyway to work around this, than to go to the database and manually edit all the data with escape character? Perhaps a way to replace the auto-escape the single-quote after it got retrieve from the db?
UPDATED
Apparently this is not due to single quote issue, but a special single quote call right single quote mark. Check http://unicodelookup.com/#’'/1
Found another one , which is – and -. Refer to http://unicodelookup.com/#–-/1
. The first one will cause the json_encode not to return anything.
Another one is “ and ". http://unicodelookup.com/#“"/1