PDA

View Full Version : Regex Query



halifaxer
12-31-2007, 02:16 PM
I have this very useful following code


<?php

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

$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] ) ) );
}
}
}

print_r ( $out );

?>

What I need to do is have $out or another similar variable define just "22.54" without returning "Array ( [original] => 36.00 [current] => 22.54 )" which it does at the moment.

The original price is of no relevance and I don't need it really, I just need the current price defined so i can use UPDATE with mySQL.

many thanks in advance and a HAPPY NEW YEAR! :p

Master_script_maker
01-01-2008, 05:58 PM
print_r ( $out['current'] );

Twey
01-01-2008, 11:35 PM
$out = $out['current'];

halifaxer
01-02-2008, 12:58 AM
thank you very much.

one question. how would i now change this to co-ordinate with


$url = 'http://www.adonisgrooming.com/product.php?productid=6947&cat=1363&page=1'

i have tinkered with it and can't get it to work. the only difference being that the tags for this code only return "£xx.xx" as opposed to "Our Price £xx.xx"

many thanks again

oh, plus this is the parameter tags
<SPAN id="product_price">£35.25
</SPAN>

i'm at a bit of a loss as to how to change this code to just get the current price. the original price is kinda useless to me but every time i try to touch the code i wreck it. lol.

anyways, happy new year and yee-hah! :)