John_S Posted March 31, 2009 Share Posted March 31, 2009 Hello there everybody! As the title says I am searching a way to get content from a table on an external webpage. I tried what I could but without any results. I proceeded this way:First I get content from the page with: <?php $source = file_get_contents('URL'); ?> Then I isolate the table I need the info from: <?phppreg_match_all('#<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=1 WIDTH=100%>(.*?)</TABLE>#s', $source, $entries); But when I arrive there, I don't know how to extract table rows and the info I need. The structure of a table row looks like <TR BGCOLOR=" DEPENDS ON THE ROW "><TD WIDTH=10%>Info I need 1</TD><TD WIDTH=55%><A HREF=" AN URL">Info I need 2</A></TD><TD WIDTH=15%>Info I need 3</TD><TD WIDTH=20%>Info I need 4</TD></TR> Does anybody know how I can get that info? Thanks a lot in advance!Yours John_S Link to comment https://forums.phpfreaks.com/topic/151969-solved-retrieving-info-from-a-table-on-a-web-page-how-can-i-do-that/ Share on other sites More sharing options...
Maq Posted March 31, 2009 Share Posted March 31, 2009 well preg_match_all() returns and array of all the matches. So all you have to do is just loop through them. foreach($entries AS $entry) echo $entry . " " ?> You just have to incorporate $entry into your table. Hope this is what you're looking for. Link to comment https://forums.phpfreaks.com/topic/151969-solved-retrieving-info-from-a-table-on-a-web-page-how-can-i-do-that/#findComment-798055 Share on other sites More sharing options...
John_S Posted March 31, 2009 Author Share Posted March 31, 2009 Hello there, Thanks a lot for your answer! Well I actually manage to isolate the table I need, the problem I have is to get the pieces of information that I need from the table rows. I don't get how to do it Link to comment https://forums.phpfreaks.com/topic/151969-solved-retrieving-info-from-a-table-on-a-web-page-how-can-i-do-that/#findComment-798081 Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 strip_tags on the data... <?php $cols = array(); // initiate the array. foreach($entries AS $entry) $cols[] = rim(strip_tags($entry)); // remove the html tags and trim for good measure. echo "<pre>", print_r($cols), "</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/151969-solved-retrieving-info-from-a-table-on-a-web-page-how-can-i-do-that/#findComment-798145 Share on other sites More sharing options...
John_S Posted April 1, 2009 Author Share Posted April 1, 2009 Hello there, Thanks a lot for your help but sadly when I try that code, I don't have any display at all, the page is blank. Is that normal? Link to comment https://forums.phpfreaks.com/topic/151969-solved-retrieving-info-from-a-table-on-a-web-page-how-can-i-do-that/#findComment-798520 Share on other sites More sharing options...
premiso Posted April 1, 2009 Share Posted April 1, 2009 It just means display_errors is set to off. I had an error in the code. <?php $cols = array(); // initiate the array. foreach($entries AS $entry) $cols[] = trim(strip_tags($entry)); // remove the html tags and trim for good measure. echo "<pre>", print_r($cols), "</pre>"; ?> Just remember it does need the code to populate the entries array to fully work. Link to comment https://forums.phpfreaks.com/topic/151969-solved-retrieving-info-from-a-table-on-a-web-page-how-can-i-do-that/#findComment-798625 Share on other sites More sharing options...
John_S Posted April 1, 2009 Author Share Posted April 1, 2009 Thanks a lot! Yes indded by default the display_error was set to off, and I didn't notice until now. Thanks a lot for your code, it worked exactly as I needed Link to comment https://forums.phpfreaks.com/topic/151969-solved-retrieving-info-from-a-table-on-a-web-page-how-can-i-do-that/#findComment-798890 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.