Extract table information from website and display on PHP page

07-16-10, 04:55 AM
|
|
New Member
|
|
Join Date: Jul 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Extract table information from website and display on PHP page
Hi,
I am working on a website for a friend. He has asked me to extract table results from a webpage ( Breaking Vehicles | Used Car Parts | Leon Recycling Ltd & Car Dismantlers Wicklow) and display on his website.
How do i go about retrieving this information, and placing it on a new php page?
Can do basic! i mean basic websites, so all help would be grateful.
Thanks for your help.
Ray Mantle
|

07-16-10, 05:08 PM
|
|
Aspiring Coder
|
|
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
|
|
|
|
|
The Following User Says Thank You to Jcbones For This Useful Post:
|
|

07-22-10, 06:03 AM
|
|
Newbie Coder
|
|
Join Date: Apr 2010
Posts: 22
Thanks: 36
Thanked 0 Times in 0 Posts
|
|
you can do it by using
file_get_contents('http://www.partfinder.ie/leon-recycling/listvehiclesforbreaking.pl');
__________________
PHP
|

07-22-10, 03:16 PM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
Lets take Jcbones code a little further and create a table just like the one you see at PartFinder.ie - Car Dismantlers, Car Breakers search for Ireland. website.
The colors maybe slightly different, but you can fix them to what ever colors you prefer.
PHP Code:
<?php $str = file_get_contents('http://www.partfinder.ie/leon-recycling/listvehiclesforbreaking.pl'); $pattern = '~<table width="750" height="600" border="0" cellspacing="5" cellpadding="4">(<tr>((<td.*>([A-Za-z0-9])*</td>)+)</tr>)*</table>~i'; preg_match($pattern,$str,$match); $match = preg_replace('~BGCOLOR=#[a-z0-9]{6}~i','',$match[3]); $rows = explode("</TR><TR>",$match); $s=0; $pattern = array("<TD >","</TD>","<TD>","</INPUT>","</TR>","</table>","</div>","</center>"); $replace = array("","|","|","","","","",""); foreach($rows AS $row) { $row = str_replace($pattern,$replace,$row); $row = str_replace("||","|",$row); if($s==0){$r = substr($row,1,strlen($row)-2);$s=1;} else{$r = substr($row,0,strlen($row)-1);} $cols[] = explode("|",$r); } $s=0; echo "<center><div style='padding:5px;background:#77b;width:815px;'><div style='background:#bbf;padding:10px;padding-left:15px;padding-right:15px;'><div style='width:770px;background:#bbf;height:500px;overflow:auto;'><table width='750' height='600' border='0' cellspacing='5' cellpadding='4' style='background:#bbf;'>"; for($row=0;$row<count($cols);$row++) { $c1=($c1=="#ddf")?"#eee":"#ddf"; if($s==0){$c="";$s=1;} else{$c="style='background:".$c1.";'";} echo "<tr>"; for($col=0;$col<count($cols[0]);$col++) { echo "<td ".$c.">".$cols[$row][$col]."</td>"; } echo "</tr>"; } echo "</table></div></div></div></center>"; ?>
__________________
Jerry Broughton
|
|
The Following 2 Users Say Thank You to job0107 For This Useful Post:
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|