Skip to content

Instantly share code, notes, and snippets.

@firefoxrebo
Created March 4, 2015 20:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firefoxrebo/4b0b57b836fd515cafb4 to your computer and use it in GitHub Desktop.
Save firefoxrebo/4b0b57b836fd515cafb4 to your computer and use it in GitHub Desktop.
Calculates the arabic string length in PHP v1
function arStringLength($str)
{
if(mb_detect_encoding($str) == 'UTF-8') {
$str = utf8_decode($str);
}
return strlen($str);
}
@firefoxrebo
Copy link
Author

Please use the function and feed me back

@w3programer
Copy link

استااااااااااااااااذ

@angelisma
Copy link

كبيييييييير

@mgomma
Copy link

mgomma commented Mar 5, 2015

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

@khalidco
Copy link

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