字符扩展ascii显示PHP

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符扩展ascii显示PHP相关的知识,希望对你有一定的参考价值。

我有一个代码,打印正确的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

答案

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

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

以上是关于字符扩展ascii显示PHP的主要内容,如果未能解决你的问题,请参考以下文章