简体   繁体   English

Strlen()和非拉丁字符

[英]Strlen() and Non-Latin Characters

I have this code case strlen($search_term) > 15: in my switch statement. 我的switch语句中有以下代码case strlen($search_term) > 15: I cannot figure out why Greek characters are parsed different. 我不知道为什么希腊字符被解析为不同。 For example a string in Latin with the length of 10 passes the case but if the string is in Greek, it does not. 例如,长度为10的拉丁文string通过case但如果string为希腊文则不能通过。

Except the solution i would appreciate an explanation of my problem. 除了解决方案外,我将对我的问题做出解释。

strlen() returns the bytes of the string, not the length. strlen()返回字符串的字节 ,而不是长度。

Many greek characters are 2 bytes instead of 1, thats why you think you take wrong results. 许多希腊字符是2个字节而不是1个字节,这就是为什么您认为自己得到错误的结果的原因。

Use mb_strlen() instead : http://lt.php.net/manual/en/function.mb-strlen.php 使用mb_strlen()代替: http : mb_strlen()

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM