3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<rss version="2.0" xmlns:a10="http://www.w3.org/2005/Atom"> <channel> <title>mMin title</title> <description>Some description</description> <managingEditor>john.doe@example.com</managingEditor> <category>Some category</category> <item> <guid isPermaLink="false">1</guid> <link>https://example.com/1</link> <title>Some title 1</title> <a10:updated>2017-05-30T13:20:22+02:00</a10:updated> <a10:content type="text/xml"> <Location>San diego</Location> <PublishedOn>2016-10-21T11:21:07</PublishedOn> <Body>Lorem ipsum dolar</Body> <JobCountry>USA</JobCountry> </a10:content> </item> <item> <guid isPermaLink="false">1</guid> <link>https://example.com/2</link> <title>Some title 2</title> <a10:updated>2017-05-30T13:20:22+02:00</a10:updated> <a10:content type="text/xml"> <Location>Detroit</Location> <PublishedOn>2016-10-21T11:21:07</PublishedOn> <Body>Lorem ipsum dolar</Body> <JobCountry>USA</JobCountry> </a10:content> </item> <item> <guid isPermaLink="false">1</guid> <link>https://example.com/3</link> <title>Some title 3</title> <a10:updated>2017-05-30T13:20:22+02:00</a10:updated> <a10:content type="text/xml"> <Location>Los Angeles</Location> <PublishedOn>2016-10-21T11:21:07</PublishedOn> <Body>Lorem ipsum dolar</Body> <JobCountry>USA</JobCountry> </a10:content> </item> </channel> </rss>'; $dom = new DOMDocument(); $dom->loadXML($xml); $items = $dom->getElementsByTagName('item'); $array = array(); foreach($items as $item) { $title = $item->getElementsByTagName('title')->item(0)->nodeValue; $link = $item->getElementsByTagName('link')->item(0)->nodeValue; $updated = $item->getElementsByTagName('updated')->item(0)->nodeValue; $location = $item->getElementsByTagName('Location')->item(0)->nodeValue; $pub = $item->getElementsByTagName('PublishedOn')->item(0)->nodeValue; $body = $item->getElementsByTagName('Body')->item(0)->nodeValue; $job = $item->getElementsByTagName('JobCountry')->item(0)->nodeValue; $array[] = [ 'title' => $title, 'link' => $link, 'updated' => $updated, 'Location' => $location, 'PublishedOn' => $pub, 'Body' => $body, 'JobCountry' => $job, ]; } var_dump($array);
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array(3) { [0]=> array(7) { ["title"]=> string(12) "Some title 1" ["link"]=> string(21) "https://example.com/1" ["updated"]=> string(25) "2017-05-30T13:20:22+02:00" ["Location"]=> string(9) "San diego" ["PublishedOn"]=> string(19) "2016-10-21T11:21:07" ["Body"]=> string(17) "Lorem ipsum dolar" ["JobCountry"]=> string(3) "USA" } [1]=> array(7) { ["title"]=> string(12) "Some title 2" ["link"]=> string(21) "https://example.com/2" ["updated"]=> string(25) "2017-05-30T13:20:22+02:00" ["Location"]=> string(7) "Detroit" ["PublishedOn"]=> string(19) "2016-10-21T11:21:07" ["Body"]=> string(17) "Lorem ipsum dolar" ["JobCountry"]=> string(3) "USA" } [2]=> array(7) { ["title"]=> string(12) "Some title 3" ["link"]=> string(21) "https://example.com/3" ["updated"]=> string(25) "2017-05-30T13:20:22+02:00" ["Location"]=> string(11) "Los Angeles" ["PublishedOn"]=> string(19) "2016-10-21T11:21:07" ["Body"]=> string(17) "Lorem ipsum dolar" ["JobCountry"]=> string(3) "USA" } }
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/E0UXJ on line 64
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/E0UXJ on line 64
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/E0UXJ on line 56
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
Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/E0UXJ on line 56
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/E0UXJ on line 56
Process exited with code 255.

preferences:
98.02 ms | 3220 KiB | 4 Q