User Security for XML

What is the best practice for generating valid XML with PHP from user-submitted text, for example. eCommerce sales data with ampersands, angle brackets, accents without ascii, newlines, etc. etc.

What functions, libraries, regular expressions do people use?

+5
source share
4 answers

Wrap information in tags CDATAand encode data withhtmlentities()

'<tag><![CDATA[' . htmlentities($theData) . ']]></tag>'

Or using the DOM

$dom = new DOMDocument("1.0", "utf-8");

/* ... */

$dom->createCDATASection(htmlentities($theData));
+4
source

, . , base64 uuencode XML-.

+1

You can also try:

html_entity_decode ()

0
source

All Articles