note 29914 deleted from function.utf8-decode by didou

From: Date: Tue, 25 Nov 2003 10:25:42 +0000
Subject: note 29914 deleted from function.utf8-decode by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60957@lists.php.net to get a copy of this message
Note Submitter: goran_johansson@yahoo.com ---- 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; }

« previous php.notes (#60957) next »