Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get DIV content from external Website

Tags:

I want to get a DIV from an external website with pure PHP.

External website: http://www.isitdownrightnow.com/youtube.com.html

Div text I want from isitdownrightnow (statusup div): <div class="statusup">The website is probably down just for you...</div>

I already tried file_get_contents with DOMDocument and str_get_html, but I could not get it to work.

For example this

$page = file_get_contents('http://css-tricks.com/forums/topic/jquery-selector-div-variable/');     $doc = new DOMDocument();     $doc->loadHTML($page);     $divs = $doc->getElementsByTagName('div');     foreach($divs as $div) {         // Loop through the DIVs looking for one withan id of "content"         // Then echo out its contents (pardon the pun)         if ($div->getAttribute('class') === 'bbp-template-notice') {              echo $div->nodeValue;         }     } 

It will just display an error in the console:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

like image 297
Kallewallex Avatar asked Dec 07 '13 21:12

Kallewallex


People also ask

How do I put an external website inside a div?

To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.

How do I show an external website inside another page without an iframe?

We can use the object tag in HTML to embed external resources in the webpage. We can use the tag to display another webpage in our webpage. The object tag is an alternative to the iframe tag in HTML. We can use the tag to embed different multimedia components like image, video, audio, etc.

How do I display one HTML page inside another?

HTML Iframe SyntaxThe HTML <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.


1 Answers

This is what I always use:

$url = 'https://somedomain.com/somesite/'; $content = file_get_contents($url); $first_step = explode( '<div id="thediv">' , $content ); $second_step = explode("</div>" , $first_step[1] );  echo $second_step[0]; 
like image 185
FlyingLemon Avatar answered Nov 30 '22 06:11

FlyingLemon