Following my recent question regarding regex with HTML that has been answered here (thank you all), I made decision to stick with regex for the last time. My goal was to grab value updateXXXX from the following HTML code using cURL:
在回答了我最近关于regex与HTML的问题之后(谢谢大家),我最后一次决定继续使用regex。我的目标是使用cURL从以下HTML代码获取值updateXXXX:
(...)<input type="hidden" id="_postupdate" name="_postupdate" value="updateXXXX" /><input type="hidden"(...)
Using
使用
$regex = '/name="_postupdate" value="([^"]*)" \/><input type="hidden"/s';
if ( preg_match($regex, $page, $list) )
echo $list[0];
i managed to get this output:
我设法得到了这个输出:
name="_postupdate" value="updateXXXX" />
I'm sure there is a simple way to remove:
我相信有一种简单的方法可以去除:
name="_postupdate" value="
and
和
" />
Once again, thanks for all advice and help :)
再次感谢您的建议和帮助。
2 个解决方案
#1
2
Change echo $list[0];
to echo $list[1];
改变echo $[0]列表;echo $列表[1];
You're currently outputting the whole match, when you just want the captured group ([^"]*)
.
你现在输出整个比赛,当你想捕获组([^]*)。
#2
1
There should be the real result in $list[1]. Try print_r($list).
在$list[1]中应该有真实的结果。试print_r(列表)。
#1
2
Change echo $list[0];
to echo $list[1];
改变echo $[0]列表;echo $列表[1];
You're currently outputting the whole match, when you just want the captured group ([^"]*)
.
你现在输出整个比赛,当你想捕获组([^]*)。
#2
1
There should be the real result in $list[1]. Try print_r($list).
在$list[1]中应该有真实的结果。试print_r(列表)。