PHP中的switch语句不识别特殊字符(即UTF-8)!
我的 PHP 代码中有一个 switch 语句,即使传递给 switch 的值是 UTF-8 字符,它似乎也不会执行带有 UTF-8 字符的情况。它适用于所有其他角色。
代码:
echo $word[$i];
switch($word[$i]){
case "a": echo "aaaa"; break;
case "č": echo "aaaa"; break;
}
如果 $word[$i] 是“a”,则代码会回显“a”和“aaaa”,如果 $word[$i] 是“č”,则代码会回显“č”,但不回显“aaaa”。它只是忽略“č”的大小写。我还尝试过使用单引号。
I have one switch statement in my PHP code and it seems it doesn't execute case with the UTF-8 character even though value put to switch is UTF-8 character. It works with all other characters.
CODE:
echo $word[$i];
switch($word[$i]){
case "a": echo "aaaa"; break;
case "č": echo "aaaa"; break;
}
If the $word[$i] is "a" the code echoes "a" and "aaaa" if the $word[$i] is "č" the code echoes "č" but does not echo "aaaa". It simply ignores case with "č". I also tried case with single quotes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有一天有人需要对 utf-8 字符串使用“str_split”,这里是工作函数:
If someone will someday need to use "str_split" for utf-8 strings here is working function: