I'm working on a script that echo's only the price. If I do:
$alttag = $oNode['p'];
echo $alttag;
It will echo everything in <p></p>
.
So it will echo:
roodmerk of cafeïnevrij pak 500 gram
2 pakken
prijs per kilo 1,99
199
from the website, so you can see it echo´s 199, that´s the price but first I ONLY need 199 in the <p></p>
and I want . or , between 199 so it will show 1,99 or 1.99.
If I do:
$alttag = $oNode['p sup'];
echo $alttag;
It will only echo 99 out of <sup></sup>
If I do:
$alttag = $oNode['p sup'];
$maintag = $oNode['p']->attr('alt');
echo $maintag . $alttag;
Well... This does nothing How can I only get the 1 and 99 and place a . or , between it so it will look like 1,99 or 1.99?
<div class="item-prijs">
<p>
<cufon class="cufon cufon-canvas" alt="1" style="width: 27px; height: 42px; ">
<canvas width="47" height="43" style="width: 47px; height: 43px; top: -1px; left: -2px; "></canvas>
<cufontext>1</cufontext>
</cufon>
<sup>
<cufon class="cufon cufon-canvas" alt="99" style="width: 24px; height: 20px; ">
<canvas width="35" height="21" style="width: 35px; height: 21px; top: -1px; left: -1px; ">
</canvas><cufontext>99</cufontext>
</cufon>
</sup>
</p>
</div>
Complete code: without the includes php functions and datbase connection.
// Extracts offers from html and return in array
function extractSparOffers($url)
{
loadPqUrl($url);
//Test $dates = extractDateRange(pq('.contentdatagrid td:first'));
$oNodes = pq('.item');
if($oNodes->count() == 0) throw new Exception('No offers were found.');
foreach($oNodes as $oNode) {
$oNode = pq($oNode);
//Test $titleDescCell = $oNode['input#a']->parent();
//Test $titleDescCell['img, input']->remove();
$priceCell = $oNode['span.price1']->parent()->parent();
// Get title and description
$data['title'] = $oNode['.item-content h3'];
$data['description'] = $oNode['.item-content p'];
// Get prices (page may contain price ranges)
$alttag = $oNode['p sup'];
$maintag = $oNode['p']->attr('alt');
echo $maintag;
//echo $alttag;
//$alttags=preg_match_all('/<img[^>]*alt="([^"]*)"/i', $html, $matches);
$none = "0.00";
$data['priceBefore'] = $none;
$data['priceAfter'] = $alttag;
// $oNode['item-prijs p.sup.cufon cufon-canvas']->attr('alt') ;
// Get image
$imgNode = $oNode['img:only-child'];
if(count($imgNode) > 0)
$img = getimg('http://www.spar.nl/' . $oNode['img:only-child']->
attr('src'));
else $img = '';
$data['image'] = $img;
//Test $data['dateStart'] = $dates['start'];
//Test $data['dateEnd'] = $dates['end'];
$date =date('Y-m-d');
$data['dateStart'] = date('Y-m-d', strtotime("yesterday"));
$data['dateEnd'] = date('Y-m-d', strtotime("tomorrow"));
$data = formatOfferStrings($data);
$odTotal[] = $data;
}
return $odTotal;
}
spiderInit();
$offerData = extractSparOffers('http://www.spar.nl/aanbiedingen/');
//Test processNewOffers('Spar', $offerData, $offerData[0]['dateStart']);
processNewOffers('Spar', $offerData, $dates['start']);
?>