note 84594 added to function.htmlentities

From: Date: Mon, 21 Jul 2008 08:23:27 +0000
Subject: note 84594 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-142410@lists.php.net to get a copy of this message
On using XML generated from a php webservice, there are important things to note, the character encoding, and the interbrowser compatibility. Using HEX entities is a solution; we can combine two solutions posted previously in this thread to get special characters on XML to work. function xmlEntities($string) { $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;'); $string = preg_replace('/[^\x09\x0A\x0D\x20-\x7F]/e', '"&#".ord("$0").";"', $string); foreach (array_keys($chars) as $num) $string = str_replace("&#".$num.";", $chars[$num], $string); return $string; } when creating the XML just do something like: $result = "<node>".xmlEntities($value)."</node>" careful with the original encoding of the $value string. see ya Snevi. -------- talk to the cow ---- Server IP: 217.160.72.57 Probable Submitter: 190.200.149.209 ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- https://master.php.net/note/edit/84594 Del: integrated -- https://master.php.net/note/delete/84594/integrated Del: useless -- https://master.php.net/note/delete/84594/useless Del: bad code -- https://master.php.net/note/delete/84594/bad+code Del: spam -- https://master.php.net/note/delete/84594/spam Del: non-english -- https://master.php.net/note/delete/84594/non-english Del: in docs -- https://master.php.net/note/delete/84594/in+docs Del: other reasons-- https://master.php.net/note/delete/84594 Reject -- https://master.php.net/note/reject/84594 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142410) next »