3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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%3Aprice%3E+%3Cg%3Acondition%3Enew%3C%2Fg%3Acondition%3E%0A%3C%2Fentry%3E%0A%3C%2Ffeed%3E): Failed to open stream: rfc2397: unable to decode in /in/M6Ycl on line 30 Warning: XMLReader::open(): Unable to open source data in /in/M6Ycl on line 30 Fatal error: Uncaught Error: Data must be loaded before reading in /in/M6Ycl:38 Stack trace: #0 /in/M6Ycl(38): XMLReader->read() #1 {main} thrown in /in/M6Ycl on line 38
Process exited with code 255.
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
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 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20
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.1.6, 5.2.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.3.11, 4.4.0 - 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.

preferences:
274.06 ms | 401 KiB | 345 Q