e1seix Posted January 1, 2008 Share Posted January 1, 2008 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 https://forums.phpfreaks.com/topic/83986-wheres-the-error-with-this-script/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.