当表达式为数字时,仅获取尖括号> <之间的值。无论如何我都想得到它们。
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;
}
这是我的HTML代码:
<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>
我想要的输出是:
Array ([1] => 1027 [2] => 5611 [3] => 5396 [4] => 834006 [5] => 5601 [6] => 2182 [7] => 1458)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句