note 78972 added to function.iconv

From: Date: Mon, 05 Nov 2007 13:01:18 +0000
Subject: note 78972 added to function.iconv
Groups: php.notes 
Request: Send a blank email to php-notes+get-132014@lists.php.net to get a copy of this message
To strip bogus characters from your input (such as data from an unsanitized or other source which you can't trust to necessarily give you strings encoded according to their advertised encoding set), use the same character set as both the input and the output, with //IGNORE on the output charcter set. <?php // assuming '†' is actually UTF8, htmlentities will assume it's iso-8859 // since we did not specify in the 3rd argument of htmlentities. // This generates "&acirc;[bad utf-8 character]" // If passed to any libxml, it will generate a fatal error. $badUTF8 = htmlentities('†'); // iconv() can ignore characters which cannot be encoded in the target character set $goodUTF8 = iconv("utf-8", "utf-8//IGNORE", $badUTF8); ?> The result of the example does not give you back the dagger character which was the original input (it got lost when htmlentities was misused to encode it incorrectly, though this is common from people not accustomed to dealing with extended character sets), but it does at least give you data which is sane in your target character set. ---- Server IP: 64.71.164.2 Probable Submitter: 146.145.51.166 ---- Manual Page -- http://www.php.net/manual/en/function.iconv.php Edit -- https://master.php.net/note/edit/78972 Del: integrated -- https://master.php.net/note/delete/78972/integrated Del: useless -- https://master.php.net/note/delete/78972/useless Del: bad code -- https://master.php.net/note/delete/78972/bad+code Del: spam -- https://master.php.net/note/delete/78972/spam Del: non-english -- https://master.php.net/note/delete/78972/non-english Del: in docs -- https://master.php.net/note/delete/78972/in+docs Del: other reasons-- https://master.php.net/note/delete/78972 Reject -- https://master.php.net/note/reject/78972 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132014) next »