<?php
$html = <<<EOT
<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*1~4*0*-1*0*0"/>
<input type="hidden" class="decValue" value="1.25"/>
<input type="hidden" class="originalBetCode" value="0]SK@84899932@323698807@NB*1~4*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*3~1*0*-1*0*0"/>
<input type="hidden" class="decValue" value="4.00"/>
<input type="hidden" class="originalBetCode" value="0]SK@84899932@323698809@NB*3~1*0*-1*0*0"/>
</a>
</div>
EOT;
$DOM = new DOMDocument();
$DOM->loadHTML($html);
$xpath = new DomXpath($DOM);
$decValues = $xpath->query('//input[@class="decValue"]/@value');
$betCodes = $xpath->query('//input[@class="betCode"]/@value');
$originalBetCodes = $xpath->query('//input[@class="originalBetCode"]/@value');
$percent = 20.0 / 100.0;
$mult = 5;
foreach($arrValues as $value){
$floatValue = floatval($value[0]->nodeValue); $discountValue = $floatValue - ($percent * $floatValue);
$expr = (((($discountValue < 1)?
round($discountValue): $discountValue) - 1) * $mult); $finalValue = "*". $expr. "~". $mult. "*";
$betValue = $value[1]->nodeValue;
$repl = preg_replace('/\*(\d+)~(\d+)\*/', $finalValue, $betValue); $value[1]->nodeValue = $repl;
$value[2]->nodeValue = $repl;
}
echo $DOM->saveHTML();