1

All I want is to read from an external source 2 prices, minimum price and maximum one.

This is the external source:

<p class="mb_05 magnify_price_stores"><span>
<span class="txt_price_gray">429,11  RON</span> - <span class="txt_price_gray">678,50 RON</span>
</span> <span><span  class="gray">(de la <b>50</b> magazine)</span></span></p>

I am using this code:

     function emag() {
 $dom1 = file_get_html("http://www.shopmania.ro/telefoane-mobile/p-samsung-galaxy-y-duos-s6102-25140344");
     foreach ($dom1->find('span [class=txt_price_gray]') as $node)
   {
   $result = $node->innertext;
   $price = explode("RON", $result);
   $prices[] = $price[0];
   echo "$prices[0]";
   }}

   emag()

And I am getting this: 429,11 429,11 on $prices[0] and 678,50 on $prices[1] $prices[0] is double!

4

1 に答える 1

2

Save the values into an array as you iterate though them. Replace the

echo "$price[0]";

With

$prices[] = $price[0];

the two prices can then be accessed with $prices[0] and $prices[1]

于 2013-02-21T21:30:07.287 に答える