note 84612 deleted from function.htmlentities by cmb

From: Date: Sun, 01 Dec 2019 08:34:30 +0000
Subject: note 84612 deleted from function.htmlentities by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213305@lists.php.net to get a copy of this message
Note Submitter: snevi at im dot com dot ve ---- 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) <?php function XMLEntities($string) { $string = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '_privateXMLEntities("$0")', $string); return $string; } function _privateXMLEntities($num) { $chars = array( 128 => '&#8364;', 130 => '&#8218;', 131 => '&#402;', 132 => '&#8222;', 133 => '&#8230;', 134 => '&#8224;', 135 => '&#8225;', 136 => '&#710;', 137 => '&#8240;', 138 => '&#352;', 139 => '&#8249;', 140 => '&#338;', 142 => '&#381;', 145 => '&#8216;', 146 => '&#8217;', 147 => '&#8220;', 148 => '&#8221;', 149 => '&#8226;', 150 => '&#8211;', 151 => '&#8212;', 152 => '&#732;', 153 => '&#8482;', 154 => '&#353;', 155 => '&#8250;', 156 => '&#339;', 158 => '&#382;', 159 => '&#376;'); $num = ord($num); return (($num > 127 && $num < 160) ? $chars[$num] : "&#".$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 '&'(&) should appear in this post as a single ampersand character and not as the html entity

« previous php.notes (#213305) next »