note 84594 modified in function.htmlentities by danbrown
| From: | danbrown@php.net | Date: | Mon, 21 Jul 2008 16:29:26 +0000 |
| Subject: | note 84594 modified in function.htmlentities by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142429@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.
<?php
function xmlEntities($string)
{
$chars = array(
128 => 'â¬',
130 => 'â',
131 => 'Æ',
132 => 'â',
133 => 'â¦',
134 => 'â ',
135 => 'â¡',
136 => 'Ë',
137 => 'â°',
138 => 'Å ',
139 => 'â¹',
140 => 'Å',
142 => 'Ž',
145 => 'â',
146 => 'â',
147 => 'â',
148 => 'â',
149 => 'â¢',
150 => 'â',
151 => 'â',
152 => 'Ë',
153 => 'â¢',
154 => 'Å¡',
155 => 'âº',
156 => 'Å',
158 => 'ž',
159 => 'Ÿ');
$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.
--was--
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 => '€',
130 => '‚',
131 => 'ƒ',
132 => '„',
133 => '…',
134 => '†',
135 => '‡',
136 => 'ˆ',
137 => '‰',
138 => 'Š',
139 => '‹',
140 => 'Œ',
142 => 'Ž',
145 => '‘',
146 => '’',
147 => '“',
148 => '”',
149 => '•',
150 => '–',
151 => '—',
152 => '˜',
153 => '™',
154 => 'š',
155 => '›',
156 => 'œ',
158 => 'ž',
159 => 'Ÿ');
$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
http://php.net/manual/en/function.htmlentities.php