Hello guys,
In this code I try to get name of products -> price of products from some sites defined in $url variable Regular expression seems to work fine. However, if on the site is more than one price (some products have extra promoting prices) I am in trouble, due to the fact that the prices are not matched to the products properly.
What I want is to make this script echo product -> price expressions and, if additional extra promoting price is present it should exchange the old price. I do hope that i make this sentence clear 🙂, sorry for english mistakes.
<?php
$pattern = '/(<span class="productSpecialPriceListing">)?[0-9]{2,4},[0-9]{2}/'; //cena jako wyrażenie regularne opcjonalnie dodaje span class, której obecność później jest sprawdzana w instrukcji warunkowej
the price like a regular expression, optionally it adds span class element, which is later checked in if condition statement
$pattern1 = '/<big>(.*)<\/big>/'; //name of product in regular expression
$url = array('www.site1.pl', 'www.site2.pl', 'www.site3.pl'); //sites which i scan
for ($i=0; $i<count($url); $i++) {
$content = file_get_contents($url[$i]);
$ile = preg_match_all($pattern, $content, $matches, PREG_PATTERN_ORDER);
$ile1 = preg_match_all($pattern1, $content, $matches1, PREG_PATTERN_ORDER);
for ($b=0; $b<$ile1; $b++) {
if (strpos($matches[0][$b], 'productSpecialPriceListing') !== false) { //if the price IS promotional
$matches[0][$b] = str_replace('<span class="productSpecialPriceListing">', '', $matches[0][$b]); //remove the prefix
//I need helep in this part some filtering instructions must be put here
}
echo 'For product <strong> ' . $matches1[0][$b] . ' </strong> the price is <strong> ' . $matches[0][$b] . ' </strong> PLN <br>';
}
}
?>