sandbudd Posted July 27, 2010 Share Posted July 27, 2010 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/ Share on other sites More sharing options...
AbraCadaver Posted July 27, 2010 Share Posted July 27, 2010 http://us.php.net/manual/en/class.domdocument.php Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/#findComment-1091846 Share on other sites More sharing options...
sandbudd Posted July 28, 2010 Author Share Posted July 28, 2010 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.... Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/#findComment-1092136 Share on other sites More sharing options...
AbraCadaver Posted July 28, 2010 Share Posted July 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/#findComment-1092142 Share on other sites More sharing options...
sandbudd Posted July 28, 2010 Author Share Posted July 28, 2010 sorry spelled it wrong http://nflcarsworldwide.net/ Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/#findComment-1092156 Share on other sites More sharing options...
radar Posted July 28, 2010 Share Posted July 28, 2010 I don't know anything about the domdocument class, but what you're looking for is a div with the following parameters: <div id="right" class="sidebar"> Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/#findComment-1092161 Share on other sites More sharing options...
sandbudd Posted July 28, 2010 Author Share Posted July 28, 2010 Hey radar I know that but how do I put that into the php code above Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/#findComment-1092173 Share on other sites More sharing options...
radar Posted July 28, 2010 Share Posted July 28, 2010 Something to do with the DomDocument. Abra would be a much better person to give that information, only because i'm sure he's used the domdocument previously and i never have. though get element by id is what you're looking for... http://us.php.net/manual/en/domdocument.getelementbyid.php Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/#findComment-1092183 Share on other sites More sharing options...
Alex Posted July 28, 2010 Share Posted July 28, 2010 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()); Quote Link to comment https://forums.phpfreaks.com/topic/209043-file_get_contents/#findComment-1092189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.