Home >Backend Development >PHP Tutorial >Problem with replacing garbled characters under Mac OS X

Problem with replacing garbled characters under Mac OS X

WBOY
WBOYOriginal
2016-07-06 13:52:311245browse

God, let’s see why the code is garbled?

It hasn’t been solved for several years
Environment: under mac OS I have tested the same problem on both), please help!

<code class="php">$string = "短标题";
$o = preg_replace(array('/\s+/'), array("->"), $string);
echo $string , ' ===> ' , $o;</code>

The screenshot below is allowed, and the garbled code appears.

Problem with replacing garbled characters under Mac OS X

Reply content:

God, let’s see why the code is garbled?

It hasn’t been solved for several years
Environment: under mac OS I have tested the same problem on both), please help!

<code class="php">$string = "短标题";
$o = preg_replace(array('/\s+/'), array("->"), $string);
echo $string , ' ===> ' , $o;</code>

The screenshot below is allowed, and the garbled code appears.

Problem with replacing garbled characters under Mac OS X

Add a line in front header('Content-type: text/html; charset=utf-8'); and try it.

Problem with replacing garbled characters under Mac OS X

Looks like there’s no problem. .

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn