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('http://korben.info/feed'); if(!$file) { echo 'err cannot read file'; // TODO curl internet } else { $res = Parser::parse($file); var_dump($res); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo for korben.info failed: System error in /in/ikB4Y on line 54 Warning: file_get_contents(http://korben.info/feed): Failed to open stream: php_network_getaddresses: getaddrinfo for korben.info failed: System error in /in/ikB4Y on line 54 err cannot read file
Output for 8.0.13 - 8.0.30
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/ikB4Y on line 54 Warning: file_get_contents(http://korben.info/feed): Failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/ikB4Y on line 54 err cannot read file
Output for 8.0.0 - 8.0.12
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /in/ikB4Y on line 54 Warning: file_get_contents(http://korben.info/feed): Failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /in/ikB4Y on line 54 err cannot read file
Output for 7.3.32 - 7.3.33, 7.4.26 - 7.4.33
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: System error in /in/ikB4Y on line 54 Warning: file_get_contents(http://korben.info/feed): failed to open stream: php_network_getaddresses: getaddrinfo failed: System error in /in/ikB4Y on line 54 err cannot read file
Output for 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.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /in/ikB4Y on line 54 Warning: file_get_contents(http://korben.info/feed): failed to open stream: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /in/ikB4Y on line 54 err cannot read file

preferences:
276.03 ms | 403 KiB | 330 Q