3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xml = <<<'XML' <?xml version="1.0"?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0"> <title>The name of your data feed</title> <link href="http://www.example.com" rel="alternate" type="text/html" /> <updated>2006-06-11T18:30:02Z</updated> <author> <name>Google</name> </author> <id>tag:example.com,2006-06-11:/support/products</id> <entry> <title>Red wool sweater</title> <id>1a</id> <link href="http://www.example.com/item1-info-page.html" /> <summary>Comfortable and soft, this sweater will keep you warm on those cold winter nights.</summary> <updated>2005-10-13T18:30:02Z</updated> <g:image_link>http://www.google.com/images/google_sm.gif</g:image_link> <g:price>25</g:price> <g:condition>new</g:condition> </entry> </feed> XML; $file = 'data://text/plain;base64,'.urlencode($xml); $fileSize = strlen($xml); $readBytes = 0; $reader = new XMLReader; $reader->open($file); $dom = new DOMDocument(); $xpath = new DOMXpath($dom); $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); $xpath->registerNamespace('gi', 'http://base.google.com/ns/1.0'); // look for the first entry element while ($reader->read() && $reader->localName !== 'entry') { continue; } // while you have an entry element while ($reader->localName === 'entry') { $node = $dom->importNode($reader->expand(), TRUE); var_dump( [ 'title' => $xpath->evaluate('string(atom:title)', $entry), 'summary' => $xpath->evaluate('string(atom:summary)', $entry), 'image-link' => $xpath->evaluate('string(gi:image_link)', $entry) ] ); $readBytes += strlen($reader->readOuterXml()); printf( 'Read %s of %s bytes, %d%%', $readBytes, $fileSize, round($readBytes * 100 / $fileSize) ); // move to the next entry sibling $reader->next('entry'); }
Output for 7.1.0
Warning: XMLReader::open(data://text/plain;base64,%3C%3Fxml+version%3D%221.0%22%3F%3E%0A%3Cfeed+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2005%2FAtom%22%0Axmlns%3Ag%3D%22http%3A%2F%2Fbase.google.com%2Fns%2F1.0%22%3E%0A%3Ctitle%3EThe+name+of+your+data+feed%3C%2Ftitle%3E%0A%3Clink+href%3D%22http%3A%2F%2Fwww.example.com%22+rel%3D%22alternate%22+type%3D%22text%2Fhtml%22+%2F%3E%0A%3Cupdated%3E2006-06-11T18%3A30%3A02Z%3C%2Fupdated%3E%0A%3Cauthor%3E%0A%3Cname%3EGoogle%3C%2Fname%3E%0A%3C%2Fauthor%3E%0A%3Cid%3Etag%3Aexample.com%2C2006-06-11%3A%2Fsupport%2Fproducts%3C%2Fid%3E%0A%3Centry%3E%0A%3Ctitle%3ERed+wool+sweater%3C%2Ftitle%3E%0A%3Cid%3E1a%3C%2Fid%3E%0A%3Clink+href%3D%22http%3A%2F%2Fwww.example.com%2Fitem1-info-page.html%22+%2F%3E%0A%3Csummary%3EComfortable+and+soft%2C+this+sweater+will+keep+you+warm+on+those+cold+winter+nights.%3C%2Fsummary%3E%0A%3Cupdated%3E2005-10-13T18%3A30%3A02Z%3C%2Fupdated%3E+%0A%3Cg%3Aimage_link%3Ehttp%3A%2F%2Fwww.google.com%2Fimages%2Fgoogle_sm.gif%3C%2Fg%3Aimage_link%3E+%3Cg%3Aprice%3E25%3C%2Fg%3Apri in /in/M6Ycl on line 30 Warning: XMLReader::open(): Unable to open source data in /in/M6Ycl on line 30 Warning: XMLReader::read(): Load Data before trying to read in /in/M6Ycl on line 38
Output for 5.4.22 - 5.4.45, 5.5.5 - 7.0.14
Warning: XMLReader::read(): data://text/plain;base64,%3C%3Fxml+version%3D%221.0%22%3F%3E%0A%3Cfeed+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2005%2FAtom%22%0Axmlns%3Ag%3D%22http%3A%2F%2Fbase.google.com%2Fns%2F1.0%22%3E%0A%3Ctitle%3EThe+name+of+your+data+feed%3C%2Ftitle%3E%0A%3Clink+href%3D%22http%3A%2F%2Fwww.example.com%22+rel%3D%22alternate%22+type%3D%22text%2Fhtml%22+%2F%3E%0A%3Cupdated%3E2006-06-11T18%3A30%3A02Z%3C%2Fupdated%3E%0A%3Cauthor%3E%0A%3Cname%3EGoogle%3C%2Fname%3E%0A%3C%2Fauthor%3E%0A%3Cid%3Etag%3Aexample.com%2C2006-06-11%3A%2Fsupport%2Fproducts%3C%2Fid%3E%0A%3Centry%3E%0A%3Ctitle%3ERed+wool+sweater%3C%2Ftitle%3E%0A%3Cid%3E1a%3C%2Fid%3E%0A%3Clink+href%3D%22http%3A%2F%2Fwww.example.com%2Fitem1-info-page.html%22+%2F%3E%0A%3Csummary%3EComfortable+and+soft%2C+this+sweater+will+keep+you+warm+on+those+cold+winter+nights.%3C%2Fsummary%3E%0A%3Cupdated%3E2005-10-13T18%3A30%3A02Z%3C%2Fupdated%3E+%0A%3Cg%3Aimage_link%3Ehttp%3A%2F%2Fwww.google.com%2Fimages%2Fgoogle_sm.gif%3C%2Fg%3Aimage_link%3E+%3Cg%3Aprice%3E25%3C%2Fg%3A in /in/M6Ycl on line 38 Warning: XMLReader::read(): �-��i~��슉�m��m�q4p�y�~�ig�p��m�p6ap� 7��6m4�a@����@1�Y��7m���wav��z in /in/M6Ycl on line 38 Warning: XMLReader::read(): ^ in /in/M6Ycl on line 38
Output for 5.4.17 - 5.4.21, 5.5.0 - 5.5.4
Warning: XMLReader::read(): data://text/plain;base64,%3C%3Fxml+version%3D%221.0%22%3F%3E%0A%3Cfeed+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2005%2FAtom%22%0Axmlns%3Ag%3D%22http%3A%2F%2Fbase.google.com%2Fns%2F1.0%22%3E%0A%3Ctitle%3EThe+name+of+your+data+feed%3C%2Ftitle%3E%0A%3Clink+href%3D%22http%3A%2F%2Fwww.example.com%22+rel%3D%22alternate%22+type%3D%22text%2Fhtml%22+%2F%3E%0A%3Cupdated%3E2006-06-11T18%3A30%3A02Z%3C%2Fupdated%3E%0A%3Cauthor%3E%0A%3Cname%3EGoogle%3C%2Fname%3E%0A%3C%2Fauthor%3E%0A%3Cid%3Etag%3Aexample.com%2C2006-06-11%3A%2Fsupport%2Fproducts%3C%2Fid%3E%0A%3Centry%3E%0A%3Ctitle%3ERed+wool+sweater%3C%2Ftitle%3E%0A%3Cid%3E1a%3C%2Fid%3E%0A%3Clink+href%3D%22http%3A%2F%2Fwww.example.com%2Fitem1-info-page.html%22+%2F%3E%0A%3Csummary%3EComfortable+and+soft%2C+this+sweater+will+keep+you+warm+on+those+cold+winter+nights.%3C%2Fsummary%3E%0A%3Cupdated%3E2005-10-13T18%3A30%3A02Z%3C%2Fupdated%3E+%0A%3Cg%3Aimage_link%3Ehttp%3A%2F%2Fwww.google.com%2Fimages%2Fgoogle_sm.gif%3C%2Fg%3Aimage_link%3E+%3Cg%3Aprice%3E25%3C%2Fg%3A in /in/M6Ycl on line 38 Warning: XMLReader::read(): �-��i~��슉�m��m�q4p�y�~�ig�p��m�p6ap� 7��6m4�a@����@1�Y��7m���wav��z in /in/M6Ycl on line 38 Warning: XMLReader::read(): ^ in /in/M6Ycl on line 38 Warning: XMLReader::read(): An Error Occurred while reading in /in/M6Ycl on line 38
Output for 5.4.0 - 5.4.16
Warning: XMLReader::read(): data://text/plain;base64,%3C%3Fxml+version%3D%221.0%22%3F%3E%0A%3Cfeed+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2005%2FAtom%22%0Axmlns%3Ag%3D%22http%3A%2F%2Fbase.google.com%2Fns%2F1.0%22%3E%0A%3Ctitle%3EThe+name+of+your+data+feed%3C%2Ftitle%3E%0A%3Clink+href%3D%22http%3A%2F%2Fwww.example.com%22+rel%3D%22alternate%22+type%3D%22text%2Fhtml%22+%2F%3E%0A%3Cupdated%3E2006-06-11T18%3A30%3A02Z%3C%2Fupdated%3E%0A%3Cauthor%3E%0A%3Cname%3EGoogle%3C%2Fname%3E%0A%3C%2Fauthor%3E%0A%3Cid%3Etag%3Aexample.com%2C2006-06-11%3A%2Fsupport%2Fproducts%3C%2Fid%3E%0A%3Centry%3E%0A%3Ctitle%3ERed+wool+sweater%3C%2Ftitle%3E%0A%3Cid%3E1a%3C%2Fid%3E%0A%3Clink+href%3D%22http%3A%2F%2Fwww.example.com%2Fitem1-info-page.html%22+%2F%3E%0A%3Csummary%3EComfortable+and+soft%2C+this+sweater+will+keep+you+warm+on+those+cold+winter+nights.%3C%2Fsummary%3E%0A%3Cupdated%3E2005-10-13T18%3A30%3A02Z%3C%2Fupdated%3E+%0A%3Cg%3Aimage_link%3Ehttp%3A%2F%2Fwww.google.com%2Fimages%2Fgoogle_sm.gif%3C%2Fg%3Aimage_link%3E+%3Cg%3Aprice%3E25%3C%2Fg%3A in /in/M6Ycl on line 38 Warning: XMLReader::read(): �-��i~��슉�m��m�q4p�y�~�ig�p��m�p6ap� 7��6m4�a@����@1�Y��7m���wav��z in /in/M6Ycl on line 38 Warning: XMLReader::read(): ^ in /in/M6Ycl on line 38 Warning: XMLReader::read(): An Error Occured while reading in /in/M6Ycl on line 38
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/M6Ycl on line 46
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Parse error: syntax error, unexpected T_SL in /in/M6Ycl on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.2
<br /> <b>Parse error</b>: syntax error, unexpected T_SL in <b>/in/M6Ycl</b> on line <b>3</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
<br /> <b>Parse error</b>: parse error, unexpected T_SL in <b>/in/M6Ycl</b> on line <b>3</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error in <b>/in/M6Ycl</b> on line <b>3</b><br />
Process exited with code 255.