字符扩展ascii显示PHP

问题描述 投票:1回答:1

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

© www.soinside.com 2019 - 2024. All rights reserved.