0

Hey I am trying to read Hebrew chars from PhpMyAdmin table and it just comes out as a mess, on the table it look's fine and written in Hebrew but when I move it to php using SELECT the output is like this:

05deu05d9u05e8u05d4u05deu05d9u05e8u05d4u05deu05d9u05e8u05d4

I tried encoding the php page to utf-8 and it didn't helped my table is enconde as

utf8_general_ci

I don't know what to do..

my php code is:

$sql = "select * from sample;";


$conn = mysqli_connect($host,$username,$password,$db);

  if (!$conn->set_charset("utf8")) {
      printf("Error loading character set utf8: %s\n", $conn->error);
  } else {
      printf("Current character set: %s\n", $conn->character_set_name());
  }


$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);
}
?>
orisgoofo
  • 53
  • 1
  • 6
  • Add `header('Content-Type: text/html; charset=utf-8'); mb_internal_encoding('UTF-8');` at the top of your file. – Qirel Nov 27 '16 at 16:01
  • Thanks for the answer but it didn't changed anything at the page. – orisgoofo Nov 27 '16 at 16:37
  • Take a look at [this comment](http://php.net/manual/en/function.preg-replace.php#106981) in the PHP manual. Also check your actual file encoding, and HTML header. – Qirel Nov 27 '16 at 16:45
  • I tried it all out , I checked the encoding of the file and its utf-8 I really don't know what is the problem – orisgoofo Nov 27 '16 at 19:47

0 Answers0