note 95962 added to function.mb-detect-encoding
| From: | jimmy at powerzone dot dk | Date: | Sun, 31 Jan 2010 20:15:34 +0000 |
| Subject: | note 95962 added to function.mb-detect-encoding | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165529@lists.php.net to get a copy of this message | ||
I was in the need of a function capable of detecting whether a string was ISO-8859-1 compatible or
not. Unfortunately I was unable to get mb_detect_encoding to work. The following function does the
trick.
function IsLatin1($str)
{
return (preg_match("/^[\\x00-\\xFF]*$/u", $str) === 1);
}
var_dump(IsLatin1("abc ABC 123")); // true
var_dump(IsLatin1("abc ⬠123")); // false (because of â¬)
----
Server IP: 87.54.44.10
Probable Submitter: 85.80.149.13
----
Manual Page -- http://www.php.net/manual/en/function.mb-detect-encoding.php
Edit -- https://master.php.net/note/edit/95962
Del: integrated -- https://master.php.net/note/delete/95962/integrated
Del: useless -- https://master.php.net/note/delete/95962/useless
Del: bad code -- https://master.php.net/note/delete/95962/bad+code
Del: spam -- https://master.php.net/note/delete/95962/spam
Del: non-english -- https://master.php.net/note/delete/95962/non-english
Del: in docs -- https://master.php.net/note/delete/95962/in+docs
Del: other reasons-- https://master.php.net/note/delete/95962
Reject -- https://master.php.net/note/reject/95962
Search -- https://master.php.net/manage/user-notes.php