3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Parser { // main public static function parse($xmlData) { $res = null; libxml_use_internal_errors(true); $dom = new DOMDocument(); $dom->recover = true; if(!$dom->loadXML($xmlData)) { $res['error'] = libxml_get_errors(); libxml_clear_errors(); } else { self::read($res, $dom); } return $res; } // tools // TODO use alternate class private static function parseText($str) { return trim(htmlentities($str)); } // void private static function read(&$res, &$dom) { $rss = $dom->getElementsByTagName('rss'); if($rss->length == 0) { $res['error'] = 'No rss node.'; } else { $channel = $rss->item(0)->getElementsByTagName('channel'); if($channel->length == 0) { $res['error'] = 'No channel node.'; } else { self::getNodes($res, $channel, array('title', 'link', 'description')); } } } private static function getNode(&$res, &$channel, $name) { $node = $channel->item(0)->getElementsByTagName($name); if($node->length == 0) { $res[$name] = null; } else { $res[$name] = self::parseText($node->item(0)->nodeValue); } } private static function getNodes(&$res, &$channel, $names) { foreach($names as $name) { self::getNode($res, $channel, $name); } } } $file = file_get_contents('https://secure.php.net/feed.atom'); if(!$file) { echo 'err cannot read file'; // TODO curl internet } else { $res = Parser::parse($file); var_dump($res); }
Output for 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/P561P on line 54 Warning: file_get_contents(): open_basedir restriction in effect. File(https://secure.php.net/feed.atom) is not within the allowed path(s): (/tmp:/in:/etc) in /in/P561P on line 54 Warning: file_get_contents(https://secure.php.net/feed.atom): Failed to open stream: Operation not permitted in /in/P561P on line 54 err cannot read file
Output for 8.0.13
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/P561P on line 54 Warning: file_get_contents(https://secure.php.net/feed.atom): Failed to open stream: No such file or directory in /in/P561P on line 54 err cannot read file
Output for 7.3.32 - 7.3.33, 7.4.33
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/P561P on line 54 Warning: file_get_contents(https://secure.php.net/feed.atom): failed to open stream: No such file or directory in /in/P561P on line 54 err cannot read file
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.32
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/P561P on line 54 Warning: file_get_contents(): open_basedir restriction in effect. File(https://secure.php.net/feed.atom) is not within the allowed path(s): (/tmp:/in:/etc) in /in/P561P on line 54 Warning: file_get_contents(https://secure.php.net/feed.atom): failed to open stream: Operation not permitted in /in/P561P on line 54 err cannot read file
Output for 7.1.20, 7.2.6
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/P561P on line 54 Warning: file_get_contents(): open_basedir restriction in effect. File(https://secure.php.net/feed.atom) is not within the allowed path(s): (/tmp:/in) in /in/P561P on line 54 Warning: file_get_contents(https://secure.php.net/feed.atom): failed to open stream: Operation not permitted in /in/P561P on line 54 err cannot read file
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.2.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/P561P on line 54 Warning: file_get_contents(https://secure.php.net/feed.atom): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/P561P on line 54 err cannot read file
Output for 7.1.10

Process exited with code 137.

preferences:
182.7 ms | 401 KiB | 242 Q