3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getbody($url) { $dom = new DOMDocument; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_URL, $url); $file = curl_exec($curl); curl_close($curl); $dom->loadHTML($file); //$dom->loadHTMLFile($url); $bodies = $dom->getElementsByTagName('body'); assert($bodies->length === 1); $body = $bodies->item(0); for ($i = 0; $i < $body->children->length; $i++) { $body->remove($body->children->item($i)); } $stringbody = $dom->saveHTML($body); return $stringbody; } $url = "http://stackoverflow.com"; //$url = "http://www.barcelona.com"; $body = getbody($url); //var_dump($body); ?> <html> <head></head> <body> <?php echo "BODY ripped from: ".$url."<br/>"; echo "<textarea rows='40' cols='200' >".$body."</textarea>"; ?> </body> </html>
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/L4gNe:4 Stack trace: #0 /in/L4gNe(23): getbody('http://stackove...') #1 {main} thrown in /in/L4gNe on line 4
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Fatal error: Call to undefined function curl_init() in /in/L4gNe on line 4
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/L4gNe 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/L4gNe on line 3