note 107985 added to function.htmlentities

From: Date: Tue, 20 Mar 2012 12:46:06 +0000
Subject: note 107985 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-186742@lists.php.net to get a copy of this message
html entities does not encode all unicode characters. It encodes what it can [all of latin1], and the others slip through. &#1033; is the nasty I use. I have searched for a function which encodes everything, but in the end I wrote this. This is as simple as I can get it. Consult an ansii table to custom include/omit chars you want/don't. I'm sure it's not that fast. // Unicode-proof htmlentities. // Returns 'normal' chars as chars and weirdos as numeric html entites. function superentities( $str ){ // get rid of existing entities else double-escape $str = html_entity_decode(stripslashes($str),ENT_QUOTES,'UTF-8'); $ar = preg_split('/(?<!^)(?!$)/u', $str ); // return array of every multi-byte character foreach ($ar as $c){ $o = ord($c); if ( (strlen($c) > 1) || /* multi-byte [unicode] */ ($o <32 || $o > 126) || /* <- control / latin weirdos -> */ ($o >33 && $o < 40) ||/* quotes + ambersand */ ($o >59 && $o < 63) /* html */ ) { // convert to numeric entity $c = mb_encode_numericentity($c,array (0x0, 0xffff, 0, 0xffff), 'UTF-8'); } $str2 .= $c; } return $str2; } ---- Server IP: 87.124.126.48 Probable Submitter: 212.84.114.229 ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- https://master.php.net/note/edit/107985 Del: integrated -- https://master.php.net/note/delete/107985/integrated Del: useless -- https://master.php.net/note/delete/107985/useless Del: bad code -- https://master.php.net/note/delete/107985/bad+code Del: spam -- https://master.php.net/note/delete/107985/spam Del: non-english -- https://master.php.net/note/delete/107985/non-english Del: in docs -- https://master.php.net/note/delete/107985/in+docs Del: other reasons-- https://master.php.net/note/delete/107985 Reject -- https://master.php.net/note/reject/107985 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186742) next »