Guys dripping screw and found this

function normJsonStr($str){ $str = preg_replace_callback('/\\\\u([a-f0-9]{4})/i', create_function('$m', 'return chr(hexdec($m[1])-1072+224);'), $str); return iconv('cp1251', 'utf-8', $str); } 

How can I add this to my script?

  $sql="SELECT * FROM spacecrafttb WHERE Propellant LIKE '%$name%'"; $query=mysqli_query($con,$sql); if($query) { while($row=mysqli_fetch_array($query)) { $data[]=$row; } print(json_encode($data)); }else { echo('Not Found '); } mysqli_close($con); 

To display Cyrillic. Help someone not difficult for the first time I work with php . The JSON_UNESCAPED_UNICODE function JSON_UNESCAPED_UNICODE not work as I have php 5.3 I would be grateful!

  • You don’t know how and where in your code to call the function normJsonStr($str) , is this a question? - koks_rs
  • Yes, it is because I use print (json_encode ($ data)); how to combine it with that function - elik
  • $ row do you have this array? So take the $ row element in the while loop and call your function $row['elem'] = normJsonStr($row['elem']) then add $ row to $ data - koks_rs
  • f vjıyj gjkyjcnmş rjl - elik
  • you can code completely y - elik

1 answer 1

 while($row=mysqli_fetch_array($query)) { $row['elem'] = normJsonStr($row['elem']);// где elem имя вашего поля в таблице sql которое вы хотите обработать, возможно это Propellant $data[]=$row; } print(json_encode($data)); 
  • pancake does not fix the Russian all the same \ u - elik
  • @elik, And this is already the problem of the function, not its calling :) - koks_rs
  • You do not know how on old php Cyrillic json vyvdit? - elik
  • Try to remove preg_replace_callback from your function, I don’t understand what it is doing there. So it should work, well, it can still make sure that your Content-type is UTF-8 - koks_rs