note 84612 added to function.htmlentities

From: Date: Tue, 22 Jul 2008 01:10:10 +0000
Subject: note 84612 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-142450@lists.php.net to get a copy of this message
correction to my previous post and improvement of the function: (the post was changed by the html parser and the characters displays as they should not) function XMLEntities($string) { $string = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '_privateXMLEntities("$0")', $string); return $string; } function _privateXMLEntities($num) { $chars = array( 128 => '&amp;#8364;', 130 => '&amp;#8218;', 131 => '&amp;#402;', 132 => '&amp;#8222;', 133 => '&amp;#8230;', 134 => '&amp;#8224;', 135 => '&amp;#8225;', 136 => '&amp;#710;', 137 => '&amp;#8240;', 138 => '&amp;#352;', 139 => '&amp;#8249;', 140 => '&amp;#338;', 142 => '&amp;#381;', 145 => '&amp;#8216;', 146 => '&amp;#8217;', 147 => '&amp;#8220;', 148 => '&amp;#8221;', 149 => '&amp;#8226;', 150 => '&amp;#8211;', 151 => '&amp;#8212;', 152 => '&amp;#732;', 153 => '&amp;#8482;', 154 => '&amp;#353;', 155 => '&amp;#8250;', 156 => '&amp;#339;', 158 => '&amp;#382;', 159 => '&amp;#376;'); $num = ord($num); return (($num > 127 && $num < 160) ? $chars[$num] : "&amp;#".$num.";" ); } in the previous post, to correct the HEX values that are not rendered, the program use a for each cicle, but that introduces a mayor complexity in execution time, so, we use the ability to call functions in the preg_replace second parameter, and ceate another funcion that evaluates the ord of the character given, and if it is between 127 and 160 it returns the modified HEX value to be understood by the browser and not brake the XML (this work with dynamic XML generated form php with dynamic data from any source) p.d: the '&amp;'(&) should appear in this post as a single ampersand character and not as the html entity ---- Server IP: 200.6.154.201 Probable Submitter: 190.77.36.230 ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- https://master.php.net/note/edit/84612 Del: integrated -- https://master.php.net/note/delete/84612/integrated Del: useless -- https://master.php.net/note/delete/84612/useless Del: bad code -- https://master.php.net/note/delete/84612/bad+code Del: spam -- https://master.php.net/note/delete/84612/spam Del: non-english -- https://master.php.net/note/delete/84612/non-english Del: in docs -- https://master.php.net/note/delete/84612/in+docs Del: other reasons-- https://master.php.net/note/delete/84612 Reject -- https://master.php.net/note/reject/84612 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142450) next »