Hola,
I am very new to regex and am relying on help from other forumers to help code this. If you think you can teach me (lol) even better.
I have an affiliate website that lists products from various external websites. For obvious reasons these products are sometimes out of stock and removed or the prices changed and my websites info is then defunct and innaccurate. I was given this very helpful code from a friend, using regex, that scans the external links page and then takes the price. I have rigged coding on my website to use this info to UPDATE mySQL accordingly - solving my problem.
Thing is, while it works for one on my supplier's website, it doesn't for others. I take it it has to do with the fact that the info within the parameter tags I'm declaring to search for is different from site to site.
Here's what I have, that works:
<?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 $out['current'];
?>
The info within parameter tags being "Our Price £xx.xx". If I need to change the parameter tags to <div class="value">£34.00<font size="3"></font></div>, the info returned just being "£34.00"
... how do I edit my coding. I know regex is extremely sensitive.
One last thing, while this code is set up to grab both original and current prices, only the current price will ever be needed.
Does anyone have a better code or a more effective way of me getting the info (on its own) from within the declared tags.
Many thanks and a happy new year