note 107221 added to function.htmlentities

From: Date: Tue, 17 Jan 2012 19:16:20 +0000
Subject: note 107221 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-185680@lists.php.net to get a copy of this message
Unfortunately, this function will mangle foreign characters, for instance, そもそも我々は出 often gets turned into stuff like îáóâÃ. If you want to retain that data, then use the mb_encode_numericentity function, which will encode string ranges to unicode. Below is an implementation that encodes only special chars, so that "a" won't be converted to its unicode equivalent. <?php // Author: holdoffhunger@gmail.com // License: AGPL3 // Input: // Hello! <=> そもそも我々は出! $format_array = array( // Handle Chars 0x00 to 0x1f = White Spacing and Technical Chars 0x0000, 0x001f, 0, 0xffff, // Handle Char 0x3c = Lesser-Than Sign 0x003c, 0x003c, 0, 0xffff, // Handle Char 0x3e = Greater-Than Sign 0x003e, 0x003e, 0, 0xffff, // Handle Chars 0x007f to 0xffff = All Other Chars 0x007f, 0xffff, 0, 0xffff ); $formatted_user_input = mb_encode_numericentity($formatted_user_input, $format_array, 'UTF-8'); // Output: // Hello! &#60;=&#62; &#12381;&#12418;&#12381;&#12418;&#25105;&#12293;&#12399;&#20986;! ?> ---- Server IP: 69.147.83.197 Probable Submitter: 68.9.137.178 ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- https://master.php.net/note/edit/107221 Del: integrated -- https://master.php.net/note/delete/107221/integrated Del: useless -- https://master.php.net/note/delete/107221/useless Del: bad code -- https://master.php.net/note/delete/107221/bad+code Del: spam -- https://master.php.net/note/delete/107221/spam Del: non-english -- https://master.php.net/note/delete/107221/non-english Del: in docs -- https://master.php.net/note/delete/107221/in+docs Del: other reasons-- https://master.php.net/note/delete/107221 Reject -- https://master.php.net/note/reject/107221 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185680) next »