note 113983 added to function.mb-detect-encoding

From: Date: Wed, 25 Dec 2013 09:30:00 +0000
Subject: note 113983 added to function.mb-detect-encoding
Groups: php.notes 
Request: Send a blank email to php-notes+get-198025@lists.php.net to get a copy of this message
if the function " mb_detect_encoding" does not exist ... ... try: <?php // ---------------------------------------------------- if ( !function_exists('mb_detect_encoding') ) { // ---------------------------------------------------------------- function mb_detect_encoding ($string, $enc=null, $ret=null) { static $enclist = array( 'UTF-8', 'ASCII', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16', 'Windows-1251', 'Windows-1252', 'Windows-1254', ); $result = false; foreach ($enclist as $item) { $sample = iconv($item, $item, $string); if (md5($sample) == md5($string)) { if ($ret === NULL) { $result = $item; } else { $result = true; } break; } } return $result; } // ---------------------------------------------------------------- } // ---------------------------------------------------- ?> example / usage of: mb_detect_encoding() <?php // ------------------------------------------------------ function str_to_utf8 ($str) { if (mb_detect_encoding($str, 'UTF-8', true) === false) { $str = utf8_encode($str); } return $str; } // ------------------------------------------------------ ?> $txtstr = str_to_utf8($txtstr); ---- Server IP: 72.52.91.14 Probable Submitter: 72.52.91.14 ---- Manual Page -- http://php.net/manual/en/function.mb-detect-encoding.php Edit -- https://master.php.net/note/edit/113983 Del: integrated -- https://master.php.net/note/delete/113983/integrated Del: useless -- https://master.php.net/note/delete/113983/useless Del: bad code -- https://master.php.net/note/delete/113983/bad+code Del: spam -- https://master.php.net/note/delete/113983/spam Del: non-english -- https://master.php.net/note/delete/113983/non-english Del: in docs -- https://master.php.net/note/delete/113983/in+docs Del: other reasons-- https://master.php.net/note/delete/113983 Reject -- https://master.php.net/note/reject/113983 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#198025) next »