Tekforums

Chat => Entertainment & Technology => Topic started by: neXus on April 23, 2008, 03:40:44 AM

Title: Preg_match_all help (data from external site)
Post by: neXus on April 23, 2008, 03:40:44 AM
Hi
I am trying to grab data from an external site (with permission)


I would like the url, image and the text of each product from the featured products http://www.watercoolingshop.com/catalog/

The format I would like:

x



£







The code from the external site

 
   

 
   
   

   
 
 
   
   

   
 
 
   
   

   
 
Heat Sink Lapping Kit (with Glass) - Standard
Heat Sink Lapping Kit (with Glass) - Standard
£5.95 Excl. VAT (£6.99) Incl. VAT
1/2" Clear/UV Blue High Flex Hose (XSPC)
1/2" Clear/UV Blue High Flex Hose (XSPC)
£3.40 Excl. VAT (£4.00) Incl. VAT
EK-Mosfet ASUS 3a (X38)
EK-Mosfet ASUS 3a (X38)
£18.29 Excl. VAT (£21.49) Incl. VAT
EK-FC3870 CF - Nickel-plated
EK-FC3870 CF - Nickel-plated
£51.06 Excl. VAT (£59.99) Incl. VAT
1/2" ID Tygon R3603 Tubing
1/2" ID Tygon R3603 Tubing
£6.86 Excl. VAT (£8.06) Incl. VAT
XSPC RS360 UV Blue
XSPC RS360 UV Blue
£28.93 Excl. VAT (£33.99) Incl. VAT
Black ICE GT Stealth II
Black ICE GT Stealth II
£26.37 Excl. VAT (£30.98) Incl. VAT
Feser One Coolant 1ltr (UV Black)
Feser One Coolant 1ltr (UV Black)
£6.80 Excl. VAT (£7.99) Incl. VAT
1/2" Green/UV Green High Flex Hose (XSPC)
1/2" Green/UV Green High Flex Hose (XSPC)
£3.40 Excl. VAT (£4.00) Incl. VAT


I know I will need to pass into some variables to echo them and to use Preg_match_all but I do not quite understand its use and function to get the data I want, I have been using:
$url = "http://www.premierleague.com/";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ch, CURLOPT_URL,$url); // the url to fetch the data
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
$result = curl_exec($ch); // run the whole process
curl_close($ch);
preg_match_all (/\)

preg_match_all(/\>([A-Za-z\s]+)\<\/a\>\<\/td\>/,$result,$clubs);
preg_match_all(/id="playedMatches"\>(\d{1,})\<\/td\>/,$result,$playedGame);
preg_match_all(/id="pts"\>(\d{1,})\<\/td\>/,$result,$points);
echo "";
for ($i=0;$iecho "";
}
echo "
TeamPldPts
".$clubs[1][$i]."".$playedGame[1][$i]."".$points[1][$i]."
";
?>

To work off to get the function I am after