我在PHP“S * +%2YKΠ3)3Π+)+Θ”中有字符串,我想迭代。
我的代码:
$string = "S*+%2YKΠ3)3Π+)+Θ";
$charLength = mb_strlen($string);
for($i = 0 ; $i < $charLength ; $i++) {
$char = mb_substr($string, $i , 1);
if($char == 'Π') {
echo "this is my Π character";
}
}
但是我从来没有输入echo语句来得到“这是我的Π角色”,
有人帮我解决这个问题,请... 我已经在寻找其他答案,如:
How to convert any character encoding to UTF8 on PHP
Convert utf8-characters to iso-88591 and back in PHP
PHP: Convert any string to UTF-8 without knowing the original character set, or at least try
How to convert a string to utf-8 code in php
但从不为我的情况工作。谢谢
答案 0 :(得分:0)
这样的代码很好,但是存在许多可能的缺陷:
mb
函数他们应该使用什么编码。将编码单独传递给每个编码(例如mb_strlen($string, 'UTF-8')
),或使用mb_internal_encoding
为所有编码设置一次。