fork download
  1. <?php
  2.  
  3. $html = <<<EOT
  4. <div id="isOffered">
  5.   <a class="price " href="javascript:;">
  6.   <span class="priceText wide UK">1/4</span>
  7.   <span class="priceText wide EU">1.25</span>
  8.   <span class="priceText wide US">-400</span>
  9.   <span class="priceText wide CH">1.25</span>
  10.   <span class="priceChangeArrow" ></span>
  11.   <input type="hidden" class="betCode" value="0]SK@84899932@323698807@NB*1~4*0*-1*0*0"/>
  12.   <input type="hidden" class="decValue" value="1.25"/>
  13.   <input type="hidden" class="originalBetCode" value="0]SK@84899932@323698807@NB*1~4*0*-1*0*0"/>
  14.   </a>
  15. </div>
  16.  
  17. <div id="isOffered">
  18.   <a class="price " href="javascript:;">
  19.   <span class="priceText wide UK">3/1</span>
  20.   <span class="priceText wide EU">4.00</span>
  21.   <span class="priceText wide US">+300</span>
  22.   <span class="priceText wide CH">4.00</span>
  23.   <span class="priceChangeArrow" ></span>
  24.   <input type="hidden" class="betCode" value="0]SK@84899932@323698809@NB*3~1*0*-1*0*0"/>
  25.   <input type="hidden" class="decValue" value="4.00"/>
  26.   <input type="hidden" class="originalBetCode" value="0]SK@84899932@323698809@NB*3~1*0*-1*0*0"/>
  27.   </a>
  28.  </div>
  29. EOT;
  30.  
  31.  
  32. $DOM = new DOMDocument();
  33. $DOM->loadHTML($html);
  34. $xpath = new DomXpath($DOM);
  35.  
  36. $decValues = $xpath->query('//input[@class="decValue"]/@value');
  37. $betCodes = $xpath->query('//input[@class="betCode"]/@value');
  38. $originalBetCodes = $xpath->query('//input[@class="originalBetCode"]/@value');
  39.  
  40. $arrValues = array_map(null, iterator_to_array($decValues),
  41. iterator_to_array($betCodes),
  42. iterator_to_array($originalBetCodes));
  43.  
  44. $percent = 20.0 / 100.0;
  45. $mult = 5;
  46.  
  47. foreach($arrValues as $value){
  48. $floatValue = floatval($value[0]->nodeValue);
  49. $discountValue = $floatValue - ($percent * $floatValue);
  50. $expr = (((($discountValue < 1)? round($discountValue): $discountValue) - 1) * $mult);
  51. $finalValue = "*". $expr. "~". $mult. "*";
  52.  
  53. $betValue = $value[1]->nodeValue;
  54. $repl = preg_replace('/\*(\d+)~(\d+)\*/', $finalValue, $betValue);
  55. $value[1]->nodeValue = $repl;
  56. $value[2]->nodeValue = $repl;
  57. }
  58.  
  59. echo $DOM->saveHTML();
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://w...content-available-to-author-only...3.org/TR/REC-html40/loose.dtd">
<html><body><div id="isOffered">      
    <a class="price  " href="javascript:;">
        <span class="priceText wide  UK">1/4</span>
        <span class="priceText wide  EU">1.25</span>
        <span class="priceText wide  US">-400</span>
        <span class="priceText wide  CH">1.25</span>
        <span class="priceChangeArrow"></span>
        <input type="hidden" class="betCode" value="0]SK@84899932@323698807@NB*0~5*0*-1*0*0"><input type="hidden" class="decValue" value="1.25"><input type="hidden" class="originalBetCode" value="0]SK@84899932@323698807@NB*0~5*0*-1*0*0"></a>
</div>

<div id="isOffered">      
    <a class="price  " href="javascript:;">
        <span class="priceText wide  UK">3/1</span>
        <span class="priceText wide  EU">4.00</span>
        <span class="priceText wide  US">+300</span>
        <span class="priceText wide  CH">4.00</span>
        <span class="priceChangeArrow"></span>
        <input type="hidden" class="betCode" value="0]SK@84899932@323698809@NB*11~5*0*-1*0*0"><input type="hidden" class="decValue" value="4.00"><input type="hidden" class="originalBetCode" value="0]SK@84899932@323698809@NB*11~5*0*-1*0*0"></a>
 </div></body></html>