用php通过preg_match_all提取内容
<formaction="/11"method="post"><inputtype="submit"value="提交"/><ahref="123">y2k</a>&nb...
<form action="/11" method="post">
<input type="submit" value="提交"/><a href="123">y2k</a> <span class="tm">20:27</span>
<input name="command_no" type="hidden" value="122008"/>
<input name="yid" type="hidden" value="21311"/>
<input name="wid" type="hidden" value="2221"/>
<input name="cid" type="hidden" value="q"/>
<input name="uid" type="hidden" value="710"/>
<input name="username" type="hidden" value="y2k"/>
<input name="uscore" type="hidden" value="0"/>
<input name="score" type="hidden" value="0"/>
<input name="content" type="hidden" value="111"/>
<input type="hidden" name="did" value="duck"/><input type="hidden" name="from" value="0"/><input type="hidden" name="page_type" value="1"/><input type="hidden" name="uid" value="ol1302368150_205"/><input type="hidden" name="putmail" value="y2k@gmail.com"/><input type="hidden" name="street" value="0"/><input type="hidden" name="front" value="0"/><input type="hidden" name="stop" value="5"/></div>
</form>
....忽略代码......
<form action="/11" method="post">
<input type="submit" value="提交"/><a href="123">got</a> <span class="tm">20:27</span>
<input name="command_no" type="hidden" value="122008"/>
<input name="yid" type="hidden" value="24511"/>
<input name="wid" type="hidden" value="23321"/>
<input name="cid" type="hidden" value="r"/>
<input name="uid" type="hidden" value="810"/>
<input name="username" type="hidden" value="gok"/>
<input name="uscore" type="hidden" value="0"/>
<input name="score" type="hidden" value="0"/>
<input name="content" type="hidden" value="112"/>
<input type="hidden" name="did" value="duck"/><input type="hidden" name="from" value="0"/><input type="hidden" name="page_type" value="1"/><input type="hidden" name="uid" value="ol1302223150_205"/><input type="hidden" name="putmail" value="got@gmail.com"/><input type="hidden" name="street" value="0"/><input type="hidden" name="front" value="0"/><input type="hidden" name="stop" value="5"/></div>
</form>
....忽略代码......
能不能通过preg_match_all来提取两个表单,并提取到表单里面的所有提交的内容呢?谢谢 展开
<input type="submit" value="提交"/><a href="123">y2k</a> <span class="tm">20:27</span>
<input name="command_no" type="hidden" value="122008"/>
<input name="yid" type="hidden" value="21311"/>
<input name="wid" type="hidden" value="2221"/>
<input name="cid" type="hidden" value="q"/>
<input name="uid" type="hidden" value="710"/>
<input name="username" type="hidden" value="y2k"/>
<input name="uscore" type="hidden" value="0"/>
<input name="score" type="hidden" value="0"/>
<input name="content" type="hidden" value="111"/>
<input type="hidden" name="did" value="duck"/><input type="hidden" name="from" value="0"/><input type="hidden" name="page_type" value="1"/><input type="hidden" name="uid" value="ol1302368150_205"/><input type="hidden" name="putmail" value="y2k@gmail.com"/><input type="hidden" name="street" value="0"/><input type="hidden" name="front" value="0"/><input type="hidden" name="stop" value="5"/></div>
</form>
....忽略代码......
<form action="/11" method="post">
<input type="submit" value="提交"/><a href="123">got</a> <span class="tm">20:27</span>
<input name="command_no" type="hidden" value="122008"/>
<input name="yid" type="hidden" value="24511"/>
<input name="wid" type="hidden" value="23321"/>
<input name="cid" type="hidden" value="r"/>
<input name="uid" type="hidden" value="810"/>
<input name="username" type="hidden" value="gok"/>
<input name="uscore" type="hidden" value="0"/>
<input name="score" type="hidden" value="0"/>
<input name="content" type="hidden" value="112"/>
<input type="hidden" name="did" value="duck"/><input type="hidden" name="from" value="0"/><input type="hidden" name="page_type" value="1"/><input type="hidden" name="uid" value="ol1302223150_205"/><input type="hidden" name="putmail" value="got@gmail.com"/><input type="hidden" name="street" value="0"/><input type="hidden" name="front" value="0"/><input type="hidden" name="stop" value="5"/></div>
</form>
....忽略代码......
能不能通过preg_match_all来提取两个表单,并提取到表单里面的所有提交的内容呢?谢谢 展开
1个回答
展开全部
<?php
$html = <<<EOT
<form action="/11" method="post">
<input type="submit" value="提交"/><a href="123">y2k</a> <span class="tm">20:27</span>
<input name="command_no" type="hidden" value="122008"/>
<input name="yid" type="hidden" value="21311"/>
<input name="wid" type="hidden" value="2221"/>
<input name="cid" type="hidden" value="q"/>
<input name="uid" type="hidden" value="710"/>
<input name="username" type="hidden" value="y2k"/>
<input name="uscore" type="hidden" value="0"/>
<input name="score" type="hidden" value="0"/>
<input name="content" type="hidden" value="111"/>
<input type="hidden" name="did" value="duck"/><input type="hidden" name="from" value="0"/><input type="hidden" name="page_type" value="1"/><input type="hidden" name="uid" value="ol1302368150_205"/><input type="hidden" name="putmail" value="y2k@gmail.com"/><input type="hidden" name="street" value="0"/><input type="hidden" name="front" value="0"/><input type="hidden" name="stop" value="5"/></div>
</form>
....忽略代码......
<form action="/11" method="post">
<input type="submit" value="提交"/><a href="123">got</a> <span class="tm">20:27</span>
<input name="command_no" type="hidden" value="122008"/>
<input name="yid" type="hidden" value="24511"/>
<input name="wid" type="hidden" value="23321"/>
<input name="cid" type="hidden" value="r"/>
<input name="uid" type="hidden" value="810"/>
<input name="username" type="hidden" value="gok"/>
<input name="uscore" type="hidden" value="0"/>
<input name="score" type="hidden" value="0"/>
<input name="content" type="hidden" value="112"/>
<input type="hidden" name="did" value="duck"/><input type="hidden" name="from" value="0"/><input type="hidden" name="page_type" value="1"/><input type="hidden" name="uid" value="ol1302223150_205"/><input type="hidden" name="putmail" value="got@gmail.com"/><input type="hidden" name="street" value="0"/><input type="hidden" name="front" value="0"/><input type="hidden" name="stop" value="5"/></div>
</form>
EOT;
$preg = '/<form\s+action="\/11".*>(.*)<\/form>/isU';
preg_match_all($preg,$html,$match);
$forms = $match[1];
$preg = '/<input\s+name="(\w+)".*value="(.*)"\/>.*/isU';
foreach ($forms as $key=>$one){
preg_match_all($preg,$one,$match);
$names = $match[1];
$values = $match[2];
print_r($names);
print_r($values);
echo '<br>';
}
exit();
?>
$html = <<<EOT
<form action="/11" method="post">
<input type="submit" value="提交"/><a href="123">y2k</a> <span class="tm">20:27</span>
<input name="command_no" type="hidden" value="122008"/>
<input name="yid" type="hidden" value="21311"/>
<input name="wid" type="hidden" value="2221"/>
<input name="cid" type="hidden" value="q"/>
<input name="uid" type="hidden" value="710"/>
<input name="username" type="hidden" value="y2k"/>
<input name="uscore" type="hidden" value="0"/>
<input name="score" type="hidden" value="0"/>
<input name="content" type="hidden" value="111"/>
<input type="hidden" name="did" value="duck"/><input type="hidden" name="from" value="0"/><input type="hidden" name="page_type" value="1"/><input type="hidden" name="uid" value="ol1302368150_205"/><input type="hidden" name="putmail" value="y2k@gmail.com"/><input type="hidden" name="street" value="0"/><input type="hidden" name="front" value="0"/><input type="hidden" name="stop" value="5"/></div>
</form>
....忽略代码......
<form action="/11" method="post">
<input type="submit" value="提交"/><a href="123">got</a> <span class="tm">20:27</span>
<input name="command_no" type="hidden" value="122008"/>
<input name="yid" type="hidden" value="24511"/>
<input name="wid" type="hidden" value="23321"/>
<input name="cid" type="hidden" value="r"/>
<input name="uid" type="hidden" value="810"/>
<input name="username" type="hidden" value="gok"/>
<input name="uscore" type="hidden" value="0"/>
<input name="score" type="hidden" value="0"/>
<input name="content" type="hidden" value="112"/>
<input type="hidden" name="did" value="duck"/><input type="hidden" name="from" value="0"/><input type="hidden" name="page_type" value="1"/><input type="hidden" name="uid" value="ol1302223150_205"/><input type="hidden" name="putmail" value="got@gmail.com"/><input type="hidden" name="street" value="0"/><input type="hidden" name="front" value="0"/><input type="hidden" name="stop" value="5"/></div>
</form>
EOT;
$preg = '/<form\s+action="\/11".*>(.*)<\/form>/isU';
preg_match_all($preg,$html,$match);
$forms = $match[1];
$preg = '/<input\s+name="(\w+)".*value="(.*)"\/>.*/isU';
foreach ($forms as $key=>$one){
preg_match_all($preg,$one,$match);
$names = $match[1];
$values = $match[2];
print_r($names);
print_r($values);
echo '<br>';
}
exit();
?>
参考资料: http://www.oscodes.net/blog-12.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询