字符扩展ASCII显示PHP



我有一个代码,可以正确打印ASCII字符至127。

$data = "Two Ts and one F.";
foreach (count_chars($data, 0) as $i => $val) {
   echo "There were $val instance(s) of " , chr($i) , " in the string.<br/>";
}

其从128到255的输出相同:

There were 0 instance(s) of � in the string.  

我将文件保存在utf-8 encoding

我想我明白了,你需要这样做: -

<?php
$data = "Two Ts and one F.";
foreach (count_chars($data, 0) as $i => $val) {
   echo "There were $val instance(s) of ". utf8_encode(chr($i)) ." in the string.".PHP_EOL;
}

输出:-https://eval.in/925240

最新更新