fork(1) download
  1. <?php
  2.  
  3. $html = <<<EOT
  4. <div id="isOffered">
  5.   <a class="price addBetButton footballBetButton" id="bk_82285689_mk_sel1" href="">
  6.   <span class="priceText wide UK">1/2</span>
  7.   <span class="priceText wide EU">1.50</span>
  8.   <span class="priceText wide US">-200</span>
  9.   <span class="priceText wide CH">1.50</span>
  10.   <span class="priceChangeArrow"></span>
  11.   <input class="betCode" type="hidden" value="0]SK@82285689@314222649@NB*1~2*0*-1*0*0]CPN:0" />
  12.   <input class="originalBetCode" type="hidden" value="0]SK@82285689@314222649@NB*1~2*0*-1*0*0]CPN:0" />
  13.   </a>
  14. </div>
  15. EOT;
  16.  
  17. $DOM = new DOMDocument();
  18. $DOM->loadHTML($html);
  19.  
  20. $xpath = new DomXpath($DOM);
  21.  
  22. $prices = $xpath->query('//*[contains(concat(" ", normalize-space(@class), " "), "priceText ")]');
  23. $percent = 20.0 / 100.0; // 20%
  24.  
  25. foreach($prices as $price){
  26. $value = $price->nodeValue;
  27. $floatValue = floatval($value);
  28. $finalValue = $floatValue - ($percent * $floatValue);
  29. echo sprintf("O valor %.2f teve um desconto de %.2f. Valor com desconto %.2f\r\n", $floatValue,
  30. $percent, $finalValue);
  31. }
  32.  
  33.  
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
O valor 1.00 teve um desconto de 0.20. Valor com desconto 0.80
O valor 1.50 teve um desconto de 0.20. Valor com desconto 1.20
O valor -200.00 teve um desconto de 0.20. Valor com desconto -160.00
O valor 1.50 teve um desconto de 0.20. Valor com desconto 1.20