note 64919 added to function.utf8-encode
| From: | info at bibliograph dot org | Date: | Sat, 22 Apr 2006 23:38:23 +0000 |
| Subject: | note 64919 added to function.utf8-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-109099@lists.php.net to get a copy of this message | ||
These two functions have worked very well for me:
<?php
function utf8_safe_decode($input)
{
if ( ! is_string ( $input ) ) return $input;
$conv = utf8_decode($input);
return ( substr_count($conv, '?') > substr_count($input, '?') ) ? $input
: $conv ;
}
function utf8_safe_encode($input)
{
if ( ! is_string ($input ) ) return $input;
$conv = utf8_decode($input);
// if input can be decoded without error, it is already utf-8
return ( substr_count($conv, '?') == substr_count($input, '?') ) ? $input :
utf8_encode($input) ;
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 84.188.228.63
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.utf8-encode.php
Edit -- http://master.php.net/note/edit/64919
Del: integrated -- http://master.php.net/note/delete/64919/integrated
Del: useless -- http://master.php.net/note/delete/64919/useless
Del: bad code -- http://master.php.net/note/delete/64919/bad+code
Del: spam -- http://master.php.net/note/delete/64919/spam
Del: non-english -- http://master.php.net/note/delete/64919/non-english
Del: in docs -- http://master.php.net/note/delete/64919/in+docs
Del: other reasons-- http://master.php.net/note/delete/64919
Reject -- http://master.php.net/note/reject/64919
Search -- http://master.php.net/manage/user-notes.php