问候全部
我正在尝试从左侧第4列获取此url的值。我可以获得所有的值,但它会跳过第一个值(例如,我认为现在最右边的值为30)
我的正则表达式是
~<td align="center" class="row2">.*<a href="javascript:who_posted.*;">([\d,]+)</a>.*</td>~isU
注意:HTML PARSING现在不是一个选项,因为这是一个巨大的系统的一部分,不能 被改变
感谢你 姆兰
答案 0 :(得分:3)
你可以使用:
/<a href="javascript:who_posted\(\d+\);?">([\d,]+)</a>/
因为javascript函数可以被用作“正则表达式选择点”
如果您希望正则表达式正常工作,则需要使用非贪婪表达式,即将.*
更改为.*?
HTML中的第一个对齐匹配属性也包含在''
引号中,而不是HTML中的""
,原因有些奇怪。试试这个:
|<td align=["\']center["\'] class="row2">.*?<a href="javascript:who_posted[^"]+">([\d,]+)</a>.*?</td>|is
修改:
$a = file_get_contents('http://www.zajilnet.com/forum/index.php?showforum=31');
preg_match_all('|<td align=["\']center["\'] class="row2">.*?<a href="javascript:who_posted[^"]+">([\d,]+)</a>.*?</td>|is',$a,$m);
print_r($m[1]);
Array
(
[0] => 30
[1] => 16
[2] => 56
[3] => 14
[4] => 96
[5] => 4
[6] => 0
[7] => 17
[.... and more....]