0

I met with a PHP messy characters issue. Although it maybe a simple or basic question, it hasn't been solved until now after hours googling. I run the following simple snippet to access an unreachable IP, and echo $errstr.

<?php
header("Content-type: text/html; charset=utf-8");
$socket = fsockopen("10.180.100.100", "23", $errno, $errstr, 3);// IP which can't access
echo $errstr."<br/>";
echo mb_detect_encoding($errstr)."<br/>";

When I run it from PHP CLI, the result is what I expect. enter image description here

When I access it from my Apache server, I get messy characters. enter image description here

I have set header("Content-type: text/html; charset=utf-8"), and set page encoding as UTF-8. Neither is helpful.

Any ideas why?

Does
  • 569
  • 6
  • 24

0 Answers0