note 71526 added to function.get-html-translation-table
| From: | zohar at zohararad dot com | Date: | Mon, 04 Dec 2006 14:31:17 +0000 |
| Subject: | note 71526 added to function.get-html-translation-table | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120267@lists.php.net to get a copy of this message | ||
Another way of converting HTML entities into numeric entities to please XML parsers is using two
arrays as conversion tables in a preg_replace function. The conversion table mechanism is based on
Ryan's examples above.
<?php
function xmlEntities($s){
//build first an assoc. array with the entities we want to match
$table1 = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
//now build another assoc. array with the entities we want to replace (numeric entities)
foreach ($table1 as $k=>$v){
$table1[$k] = "/$v/";
$c = htmlentities($k,ENT_QUOTES,"UTF-8");
$table2[$c] = "&#".ord($k).";";
}
//now perform a replacement using preg_replace
//each matched value in array 1 will be replaced with the corresponding value in array 2
$s = preg_replace($table1,$table2,$s);
return $s;
}
?>
----
Server IP: 192.117.122.43
Probable Submitter: 62.90.246.190
----
Manual Page -- http://www.php.net/manual/en/function.get-html-translation-table.php
Edit -- https://master.php.net/note/edit/71526
Del: integrated -- https://master.php.net/note/delete/71526/integrated
Del: useless -- https://master.php.net/note/delete/71526/useless
Del: bad code -- https://master.php.net/note/delete/71526/bad+code
Del: spam -- https://master.php.net/note/delete/71526/spam
Del: non-english -- https://master.php.net/note/delete/71526/non-english
Del: in docs -- https://master.php.net/note/delete/71526/in+docs
Del: other reasons-- https://master.php.net/note/delete/71526
Reject -- https://master.php.net/note/reject/71526
Search -- https://master.php.net/manage/user-notes.php