eval.in

Paste #13168

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
17
18
19
20
21
<?php
/* @link http://stackoverflow.com/q/15523672/367456
 */
$content = htmlspecialchars('Carer £4.20 per person<br />');

$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;


//create the root element
$root = $doc->appendChild(
    $doc->createElement("document")
);

$root->appendChild(
    $doc->createElement("content", $content)
);

echo "Save XML:\n", $doc->saveXML();
echo "\n\nSave HTML:\n", $doc->saveHTML();

Program Output

Save XML:
<?xml version="1.0"?>
<document>
  <content>Carer &#xA3;4.20 per person&lt;br /&gt;</content>
</document>


Save HTML:
<document><content>Carer &pound;4.20 per person&lt;br /&gt;</content></document>

OK (0.004 sec real, 0.005 sec wall, 13 MB, 45 syscalls)

Fork