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
<?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