note 50796 added to function.utf8-encode

From: Date: Thu, 10 Mar 2005 07:57:35 +0000
Subject: note 50796 added to function.utf8-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-86194@lists.php.net to get a copy of this message
Here's a function I made to know if one string or textfile is already encoded in UTF8 : <?php /** * Returns <kbd>true</kbd> if the string or array of string is encoded in UTF8. * * Example of use. If you want to know if a file is saved in UTF8 format : * <code> $array = file('one file.txt'); * $isUTF8 = isUTF8($array); * if (!$isUTF8) --> we need to apply utf8_encode() to be in UTF8 * else --> we are in UTF8 :) * </code> * @param mixed A string, or an array from a file() function. * @return boolean */ function isUTF8($string) { if (is_array($string)) { $enc = implode('', $string); return @!((ord($enc[0]) != 239) && (ord($enc[1]) != 187) && (ord($enc[2]) != 191)); } else { return (utf8_encode(utf8_decode($string)) == $string); } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.utf8-encode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50796 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50796&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50796&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50796&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50796&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50796&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50796&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86194) next »