字符扩展ascii显示PHP

时间:2017-12-26 09:20:47

标签: php encoding

我有一个代码可以正确打印ascii字符到127.但它不能正确打印ascii字符。

$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

1 个答案:

答案 0 :(得分:1)

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

<?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