3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * How to get SVG tag content with PHP * @link http://stackoverflow.com/a/16234458/367456 */ $string = <<<BUFFER <?xml version="1.0" encoding="utf-8"?> <!-- comment --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="202.5px" height="226.084px" viewBox="0 0 202.5 226.084" enable-background="new 0 0 202.5 226.084" xml:space="preserve"> <g> <path d="M0,13.628c47.7940,13.628z"/> <polygon points="108.48,207.874 145.506,196.948 145.506,204.536 108.48,214.854 "/> <path fill="none" stroke="#000000" d="M114.55,223.959"/> </g> </svg> BUFFER; $xml = simplexml_load_string('<polygon points="108.48,207.874 145.506,196.948 145.506,204.536 108.48,214.854 "/>'); $xml->registerXPathNamespace('svg', 'http://www.w3.org/2000/svg'); $xml->addAttribute('type', 'documentary'); //$xml->xpath('g/path')[0]->asXML('php://output'); print_r($xml);
Output for 5.1.3 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
SimpleXMLElement Object ( [@attributes] => Array ( [points] => 108.48,207.874 145.506,196.948 145.506,204.536 108.48,214.854 [type] => documentary ) )
Output for 5.1.2
Fatal error: Call to undefined method SimpleXMLElement::addAttribute() in /in/FTQ7X on line 25
Process exited with code 255.
Output for 5.1.0 - 5.1.1
Fatal error: Call to undefined method SimpleXMLElement::addAttribute() in /in/FTQ7X on line 24
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined method SimpleXMLElement::registerXPathNamespace() in /in/FTQ7X on line 23
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: simplexml_load_string() in /in/FTQ7X on line 21
Process exited with code 255.
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.4
Fatal error: Call to undefined function: simplexml_load_string() in /in/FTQ7X on line 21
Process exited with code 255.
Output for 4.4.2
Fatal error: Call to undefined function: simplexml_load_string() in /in/FTQ7X on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: simplexml_load_string() in /in/FTQ7X on line 21