Adapting a PHP Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ojsimon
Forum Newbie
Posts: 24
Joined: Sat Mar 31, 2007 5:01 am

Adapting a PHP Script

Post by ojsimon »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


how can i adapt this script

Code: Select all

<?php
$file=file_get_contents("http://amazon.co.uk/o/ASIN/B000BVNREY/ref=s9_asin_image_2/202-3365519-7202264?". "pf_rd_m=A3P5ROKL5A1OLE&pf_rd_s=center-3&pf_rd_r=1Q2GWW98EW6H2KYN4M1P&". "pf_rd_t=101&pf_rd_p=135090391&pf_rd_i=468294");
preg_match('/<b class="price">(.+)<\/b>/U',$file,$price);
$price=preg_replace('/<b class="price">(.+)<\/b>/U','$1',$price);
echo $price[0];
?>
to get the price off each of these
http://www.bizrate.co.uk/mobilephone...__nwylf--.html
http://phones.search.ebay.co.uk/n93_...34QQsacatZ3312
http://www.pricerunner.co.uk/cl/1/Mo...3B%3B%3B&q=n93
http://www.nextag.co.uk/Mobile-Phone...ukzB7z5---html
http://shopping.kelkoo.co.uk/ctl/do/...&fromform=true
http://froogle.google.com/froogle?q=...Search+Froogle

i changed the url but this did'nt work, how do i do this

Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The code posted is designed specifically for Amazon's site. I would suggest you continue to look for better code that is more flexible. Perhaps a class or three or even a developer API the various sites you wish to access provide.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Wild guess.. you're attempting to write a price comparison system?

I'm doing the same at the moment. My solution is to create a class to grab data from any site, with a selection of helper methods for parsing the resulting HTML, and then extend that class for each specific site that I want to fetch prices from with methods holding the required regular expression code to get the price, product and url information from pages. I've built a system to construct that object and run some standard methods on a schedule. It's pretty complicated, and at the moment it's horribly fragile.

Ideally you'd start off by porting something like Beautiful Soup (or just writing the code in Python), but that's a lot of work for what is (in my case) just a distracting little side project.
Post Reply