@ 2014-04-23T08:40:43Z <?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,'.base64encode($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');
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 , 7.2.0 - 7.2.33 , 7.3.12 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught Error: Call to undefined function base64encode() in /in/2Q9Ov:25
Stack trace:
#0 {main}
thrown in /in/2Q9Ov on line 25
Process exited with code 255 . Output for 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.7 - 5.6.28 Fatal error: Call to undefined function base64encode() in /in/2Q9Ov on line 25
Process exited with code 255 . Output for 5.3.0 - 5.3.29 Parse error: syntax error, unexpected '[', expecting ')' in /in/2Q9Ov on line 46
Process exited with code 255 . Output for 4.4.2 - 4.4.9 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Parse error: syntax error, unexpected T_SL in /in/2Q9Ov on line 3
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 Parse error: parse error, unexpected T_SL in /in/2Q9Ov on line 3
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/2Q9Ov on line 3
Process exited with code 255 . preferences:dark mode live preview
230.32 ms | 401 KiB | 315 Q