note 86878 added to function.mb-convert-encoding

From: Date: Fri, 07 Nov 2008 16:24:46 +0000
Subject: note 86878 added to function.mb-convert-encoding
Groups: php.notes 
Request: Send a blank email to php-notes+get-146287@lists.php.net to get a copy of this message
My solution below was slightly incorrect, so here is the correct version (I posted at the end of a long day, never a good idea!) Again, this is a quick and dirty solution to stop mb_convert_encoding from filling your string with question marks whenever it encounters an illegal character for the target encoding. <?php function convert_to ( $source, $target_encoding ) { // detect the character encoding of the incoming file $encoding = mb_detect_encoding( $source, "auto" ); // escape all of the question marks so we can remove artifacts from // the unicode conversion process $target = str_replace( "?", "[question_mark]", $source ); // convert the string to the target encoding $target = mb_convert_encoding( $target, $target_encoding, $encoding); // remove any question marks that have been introduced because of illegal characters $target = str_replace( "?", "", $target ); // replace the token string "[question_mark]" with the symbol "?" $target = str_replace( "[question_mark]", "?", $target ); return $target; } ?> Hope this helps someone! (Admins should feel free to delete my previous, incorrect, post for clarity) -A ---- Server IP: 66.207.199.35 Probable Submitter: 99.231.148.142 ---- Manual Page -- http://www.php.net/manual/en/function.mb-convert-encoding.php Edit -- https://master.php.net/note/edit/86878 Del: integrated -- https://master.php.net/note/delete/86878/integrated Del: useless -- https://master.php.net/note/delete/86878/useless Del: bad code -- https://master.php.net/note/delete/86878/bad+code Del: spam -- https://master.php.net/note/delete/86878/spam Del: non-english -- https://master.php.net/note/delete/86878/non-english Del: in docs -- https://master.php.net/note/delete/86878/in+docs Del: other reasons-- https://master.php.net/note/delete/86878 Reject -- https://master.php.net/note/reject/86878 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146287) next »