Created
April 11, 2011 11:22
-
-
Save supermethod/913375 to your computer and use it in GitHub Desktop.
Convert HTML entities to XML entities - optionally coverts special characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function xmlEntities($string, $specialchars = false) { | |
$translationTable = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); | |
foreach ($translationTable as $char => $entity) { | |
$from[] = $entity; | |
$to[] = '&#'.ord($char).';'; | |
} | |
//convert special characters &, ", ', <, > to html entities | |
if ($specialchars) { | |
$string = htmlspecialchars($string); | |
} | |
//convert html entities to XML entities | |
return str_replace($from, $to, $string); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment