Created
March 4, 2015 20:06
-
-
Save firefoxrebo/4b0b57b836fd515cafb4 to your computer and use it in GitHub Desktop.
Calculates the arabic string length in PHP v1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arStringLength($str) | |
{ | |
if(mb_detect_encoding($str) == 'UTF-8') { | |
$str = utf8_decode($str); | |
} | |
return strlen($str); | |
} |
استااااااااااااااااذ
كبيييييييير
That piece of code means any text encoded in utf-8 not Arabic language
If used for English text will return the same result whatever the language
This function is terrible at detecting the exact encoding. It's unreliable! It would, for example, give you ASCII when it should give you windows-1256 and thus causing you a big headache, if you want to post Arabic text on Twitter.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please use the function and feed me back