3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $html = '<a href="http://www.mydomain.com/galeria/thumbnails.php?album=774" target="_blank"><img alt="/" src="http://img255.imageshack.us/img00/000/000001.png" height="133" width="113"></a>'; $doc = new DOMDocument; $doc->loadHTML( $html); $results = array(); foreach( $doc->getElementsByTagName( 'a') as $a) { // If there are no children, continue on if( !$a->hasChildNodes()) continue; // Find the child <img> tag, if it exists foreach( $a->childNodes as $child) { if( $child->nodeType == XML_ELEMENT_NODE && $child->tagName == 'img') { // Now we have the <a> tag in $a and the <img> tag in $child // Get the information we need: parse_str( parse_url( $a->getAttribute('href'), PHP_URL_QUERY), $a_params); $results[] = array( $a_params['album'], $child->getAttribute('src')); } } } print_r( $results);
Output for 5.1.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Array ( [0] => 774 [1] => http://img255.imageshack.us/img00/000/000001.png ) )
Output for 5.0.0 - 5.1.1
Notice: Use of undefined constant PHP_URL_QUERY - assumed 'PHP_URL_QUERY' in /in/GFKXi on line 15 Warning: parse_url() expects exactly 1 parameter, 2 given in /in/GFKXi on line 15 Notice: Undefined index: album in /in/GFKXi on line 16 Array ( [0] => Array ( [0] => [1] => http://img255.imageshack.us/img00/000/000001.png ) )
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/GFKXi on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/GFKXi on line 3