Jump to content

preg_match problem


tobz

Recommended Posts

Hi

 

I'm trying to use preg_match to scrape the price of a product from a web site to do a price comparison but, for some reason that I can't work out, it is not returning the expected result.

 

Before you look at this, the URL is an "adult toys" site (not pornographic), so please don't look if that offends you!

 

OK, the URL is http://www.simplypleasure.com/products/novelties-340/chocolate-strawberry-body-pens-40g-each-3896.aspx (don't ask!)

 

My code is as follows:

 

$URL5 = "http://www.simplypleasure.com/products/novelties-340/chocolate-strawberry-body-pens-40g-each-3896.aspx";

$PAGE5 = file_get_contents($URL5);

if (preg_match('/<span class=.price.>£(\d+\.\d+)<\/span>/',$PAGE5,$matches))
$PRICE[5] = $matches[1];
else
$PRICE[5] = 'na';

 

I have tested my pattern match via this website http://www.functions-online.com/preg_match.html against the source code of the URL and it correctly returns $matches[1] as 6.00 (need to change £ to £ in that checker to get it to work).

 

I thought perhaps file_get_contents was returning spurious code but I wrote the results to a text file and it seems to be the correct source code.

 

Any ideas welcomed, thanks.

Link to comment
https://forums.phpfreaks.com/topic/252528-preg_match-problem/
Share on other sites

Hello, yes, should have made that clear, when I say for price comparison, it's for my own personal use. I'm trying to make my life easier when comparing prices across sites in the run-up to Xmas. I have similar code working checking prices on other sites but can't figure out what's happening with this particular piece of code/URL.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/252528-preg_match-problem/#findComment-1294718
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.