eval.in

Paste #10980

PHP — PHP 5.4.6, pasted 1 year ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?php
$xml = "Test &amp; <b> and encode </b> :)\n";

function xmlentities($dirty){
$doc = new DOMDocument();
$fragment = $doc->createDocumentFragment();

// adding XML verbatim:

$fragment->appendChild($doc->createTextNode($dirty));

// output the result
return $doc->saveXML($fragment);
}

echo xmlentities($xml);

Program Output

Test &amp;amp; &lt;b&gt; and encode &lt;/b&gt; :)

OK (0.008 sec real, 0.010 sec wall, 13 MB, 42 syscalls)

Fork