Current location: Hot Scripts Forums » Programming Languages » PHP » Extract table information from website and display on PHP page


Extract table information from website and display on PHP page

Reply
  #1 (permalink)  
Old 07-16-10, 04:55 AM
rayzer rayzer is offline
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-16-10, 05:08 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Something like this:
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]);
echo 
'<table><tr>' $match '</tr></table>';
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Jcbones For This Useful Post:
mysamsung (07-22-10)
  #3 (permalink)  
Old 07-22-10, 06:03 AM
mysamsung mysamsung is offline
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-22-10, 03:16 PM
job0107's Avatar
job0107 job0107 is offline
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following 2 Users Say Thank You to job0107 For This Useful Post:
Jcbones (07-23-10), mysamsung (07-23-10)
Reply

Bookmarks

Tags
display, extract, php, retrieving, webpage


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Dropdown Display seungew PHP 0 07-04-10 07:35 PM
Display PHP in HTML page using JS scott2500uk PHP 6 05-18-06 01:25 PM
how to display forum topic on main page of website ? itssami Script Requests 1 04-21-06 11:16 PM
PHP Website advanceddesigns Job Offers & Assistance 5 09-30-05 05:36 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 07:02 AM


All times are GMT -5. The time now is 10:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.