This expression only gets the values between angle brackets > < when they are numeric. I want to get them in any case.
function GetProducts($file){
$regex = "|class=\"producto\"[^>]+>([0-9]*)</[^>]+>|U";
if(!is_file($file)) return false;
preg_match_all($regex,file_get_contents($file), $result);
foreach($result[1] as $key =>$value) $result[$key] = (int) $value;
return $result;
}
This is my HTML code:
<a class="producto" href="ver.asp?id=4013">A86028</a></span><!-- /a --></td></tr>
<a class="producto" href="ver.asp?id=4014">1027C</a></span><!-- /a --></td></tr>
<a class="producto" href="ver.asp?id=4014">5611 4020</a></span>
<!-- /a --></td></tr>
<a class="producto" href="ver.asp?id=4014">396-4185</a></span>
<!-- /a --></td></tr>
<a class="producto" href="ver.asp?id=4014">834006-5-7</a></span>
<!-- /a --></td></tr>
<a class="producto" href="ver.asp?id=4014">5601GR 4325GR</a></span>
<!-- /a --></td></tr>
<a class="producto" href="ver.asp?id=4014">2182CR(2)</a></span>
<!-- /a --></td></tr>
<a class="producto" href="ver.asp?id=4014">1458-54-63-55</a></span>
<!-- /a --></td></tr>
My desired output is:
Array ([1] => 1027 [2] => 5611 [3] => 5396 [4] => 834006 [5] => 5601 [6] => 2182 [7] => 1458)