Jump to content

file_get_contents


sandbudd

Recommended Posts

This works great but I only need part of the page for example the right column...can I do this with a class or some how.  What this is is pulling information from another site.

 


<?php $g = file_get_contents("http://www.site.com/index.php");
echo ($g);
?>

Link to comment
Share on other sites

I looked there and tried a few things and it did not work... what I am trying to do is capture the right hand side of www.nflcarswoldwide.net the right hand side with the maps....

 

Well, you need to figure out what the right hand side of that page is (it didn't load for me).  If the info is in a div or a table td, then you load the page into Domdocument and extract the div, td, etc. by name, id or by count, like if is the 3rd td of the second table etc...  Find out what it is and then look at a DOM tutorial to see how to get it.

Link to comment
Share on other sites

DOM might not be the best tool in this case because their markup is invalid. If you want to use DOM you'll have to suppress the warnings generated by their HTML. Here's an example on how it could be done using DOM anyway..

 

$doc = new DOMDocument();
@$doc->loadHTMLFile('http://nflcarsworldwide.net/'); // @ to suppress warnings from their invalid HTML
$temp = new DOMDocument();
foreach ($doc->getElementById('right')->childNodes as $child){
$temp->appendChild($temp->importNode($child, true));
}
echo trim($temp->saveHTML());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.