Home Blog Tech Stuff Escaping XML Reserved Characters in PHP

Escaping XML Reserved Characters in PHP

E-mail Print PDF

I just stumbled across this function in some of my old PHP code and since I replied to an issue on the Joomla! forums only the other day about this same thing, I thought I'd post it here seeing that I have a couple of notes about XHTML already on this site:

function xmlspecialchars($text) {
   return str_replace(''', ''', htmlspecialchars($text, ENT_QUOTES));
}

I don't remember if I read through the XML specs and wrote this myself or whether I just found it somewhere, but I have a feeling I checked it all out at the time and I think this covers all the necessary escaping for XHTML...please somebody let me know if I'm mistaken!

Last Updated on Thursday, 10 September 2009 02:16