Search code examples
phpstringstrlen

Strlen() and Non-Latin Characters


I have this code case strlen($search_term) > 15: in my switch statement. 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.

Except the solution i would appreciate an explanation of my problem.


Solution

  • strlen() returns the bytes of the string, not the length.

    Many greek characters are 2 bytes instead of 1, thats why you think you take wrong results.

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

    Hope this helps