note 39517 added to function.utf8-decode
| From: | AidanKehoe | Date: | Sat, 31 Jan 2004 10:35:34 +0000 |
| Subject: | note 39517 added to function.utf8-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64474@lists.php.net to get a copy of this message | ||
The fastest way I've found to check if something is valid UTF-8 is
<?php
if (iconv('UTF-8', 'UTF-8', $input) != $input) {
/* It's not UTF-8--for me, it's probably CP1252, the Windows
version of Latin 1, with directed quotation marks and
the Euro sign. */
}
?>.
The iconv() C library fails if it's told a string is UTF-8 and it isn't; the PHP one
doesn't, it just returns the conversion up to the point of failure, so you have to compare the
result to the input to find out if the conversion succeeded.
----
Manual Page -- http://www.php.net/manual/en/function.utf8-decode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39517
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39517&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39517&report=yes
Search -- http://master.php.net/manage/user-notes.php