I have a PHP script that takes data from MySQL database and write it with echo, the problem is that it shows Hebrew as just a weird string and not the actual content, on the phpMyAdmin database it shows the Hebrew characters fine and it is encoded there to utf8_general_ci
, but when it transferred to the PHP it doesn't work.
On the PHP code I tried to encode is:
<?php
header('Content-Type: text/html; charset=utf-8');
?>
but it didn't work, the PHP code is:
$conn = mysqli_connect($host,$username,$password,$db);
$result = mysqli_query($conn,$sql);
$response = array();
while($row = mysqli_fetch_array($result))
{
array_push($response,array($row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6]));
}
$str = json_encode(array($response));
$str = clean($str);
echo $str;
mysqli_close($conn);
function clean($string) {
$string = str_replace(' ', ' ', $string);
$string = preg_replace('/[^a-zA-Z0-9,: -]/', '', $string);
return preg_replace('/-+/', '-', $string);
}
?>