Jump to content

Where's the error with this script?


e1seix

Recommended Posts

The following script...

 

$url = 'http://www.cheapsmells.com/viewProduct.php?id=6590';

$parts = array ( array ( '<div class=\'productOriginalPrice\'>', '</div>' ), array ( '<div class=\'productOurPrice\'>', '</div>' ) );

$out = array ( 'original' => '', 'current' => '' );

if ( false !== ( $page = file_get_contents ( $url ) ) )
{
foreach ( $parts AS $name => $value )
{
	if ( false !== ( $s = stripos ( $page, $value[0] ) ) )
	{
		$page = substr ( $page, $s + strlen ( $value[0] ) );

		$out[($name == 0 ? 'original' : 'current' )] = preg_replace ( '/(.+?)(\d+\.\d+)(.+?)?/is', '\\2', substr ( $page, 0, strpos ( $page, $value[1] ) ) );
	}
}
}

 

works fine, but then this...

 

$url = 'http://www.adonisgrooming.com/product.php?productid=6439&cat=1358&page=1';

$parts = array ( array ( '<SPAN id=\'product_price\'>', '</SPAN>' ), array ( '<SPAN id=\'product_price\'>', '</SPAN>' ) );

$out = array ( 'original' => '', 'current' => '' );

if ( false !== ( $page = file_get_contents ( $url ) ) )
{
foreach ( $parts AS $name => $value )
{
	if ( false !== ( $s = stripos ( $page, $value[0] ) ) )
	{
		$page = substr ( $page, $s + strlen ( $value[0] ) );

		$out[($name == 0 ? 'original' : 'current' )] = preg_replace ( '/(.+?)(\d+\.\d+)(.+?)?/is', '\\2', substr ( $page, 0, strpos ( $page, $value[1] ) ) );
	}
}
}

 

doesn't. I'm confused, although I'm no expert in regex.

 

In the first instance, the contents of the tags is eg. "Our Price £9.95"

In the second, it's eg. "£35.25"

 

I'm assuming it's something to do with

$out[($name == 0 ? 'original' : 'current' )] = preg_replace ( '/(.+?)(\d+\.\d+)(.+?)?/is', '\\2', substr ( $page, 0, strpos ( $page, $value[1] ) ) );

 

can anybody help at all.

 

many thanks :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.