I execute the following code

mysql_connect("localhost","ххх","ххх"); mysql_query("SET NAMES utf8"); mysql_select_db("ххх"); $sql=mysql_query("select * from graph"); while($row=mysql_fetch_assoc($sql)) $output[]=$row; //$str = str_replace(""","\"",$output); echo json_encode($output); mysql_close(); 

in response, I get a string with unshielded quotes ... how to shield? as you can see from the code, attempts were made to replace via str_replace, but it also did not work ..

  • four
    addslashes ()? mysql_real_escape_string ()? - Yoharny Babay
  • thank! I'm going to try now. I'm familiar with PHP for a maximum of a week ... - baralgin1003
  • If you are familiar with PHP not long ago, I advise you to read the reference book of standard functions. Believe me, very useful thing :) - Yoharny Babay

2 answers 2

str_replace() XDD) if you have chosen to screen this:

$str = str_replace("'", "\'", $output);

or

$str = str_replace('"', '\"', $output);

or better

$str = str_replace(array("'", '"'), array("\'", '\"'), $output);

but correct answer from @ Yoharny Babai

  • Again, someone made my comment reply, set up? Guys, if I think that IT is better to write in the comments, then you do not need to make it an answer. Thank! - Palmervan pm
 echo json_encode($output, JSON_HEX_QUOT); 

All characters are encoded in \ u0022. Available since PHP 5.3.0.