note 29914 added to function.utf8-decode
| From: | goran_johansson at yahoo dot com | Date: | Fri, 28 Feb 2003 15:39:23 +0000 |
| Subject: | note 29914 added to function.utf8-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44665@lists.php.net to get a copy of this message | ||
I needed a way to found out if the actual string contains Unicodechars or not before trying
utf8_decode on the string, because if it is not you will get the ugly ?-marks.
To solve this, I made this function which works for me.
function smart_utf8_decode($in_str)
{
// Replace ? with a unique string
$new_str = str_replace("?", "q0u0e0s0t0i0o0n", $in_str);
// Try the utf8_decode
$new_str=utf8_decode($in_str);
// if it contains ? marks
if (strpos($new_str,"?")>0)
{
// Something went wrong, set new_str to the original string.
$new_str=$in_str;
}
else
{
// If not then all is well, put the ?-marks back where is belongs
$new_str = str_replace("q0u0e0s0t0i0o0n", "?", $new_str);
}
return $new_str;
}
--
http://www.php.net/manual/en/function.utf8-decode.php
http://master.php.net/manage/user-notes.php?action=edit+29914
http://master.php.net/manage/user-notes.php?action=delete+29914
http://master.php.net/manage/user-notes.php?action=reject+29914