88发财分求个正则写法,从html数据流中读取数据,大家新年发财 本帖最后由 vgy12304 于 2010-02-20 13:34:20 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $str = <<<str<DIV style=\"POSITION: absolute; TOP: 19px; LEFT: 25px\" id=idDrag485 class=idfrom ondblclick=deldiv(485)> <DIV id=idHandle485 class=idtest ondblclick=deldiv(485)> <TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\"> <TBODY> <TR> <TD width=\"30%\" align=right>联系人: </TD> <TD width=\"70%\"> <INPUT class=red size=20 name=relname {Require} style="color:#000000;"> </TD> </TR> </TBODY> </TABLE> </DIV> </DIV> <DIV style=\"POSITION: absolute; TOP: 193px; LEFT: 53px\" id=idDrag267 class=idfrom ondblclick=deldiv(267)> <DIV id=idHandle267 class=idtest ondblclick=deldiv(267)> <TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\"> <TBODY> <TR> <TD width=\"30%\" align=right>性别: </TD> <TD width=\"70%\"> <INPUT class=black value={Require} type=radio name=sex> </TD> </TR> </TBODY> </TABLE> </DIV> </DIV> <DIV style=\"POSITION: absolute; TOP: 70px; LEFT: 24px\" id=idDrag456 class=idfrom ondblclick=deldiv(456)> <DIV id=idHandle456 class=idtest ondblclick=deldiv(456)> <TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\"> <TBODY> <TR> <TD width=\"30%\" align=right>兴趣: </TD> <TD width=\"70%\"> <INPUT class=blue value={Require} type=checkbox name=xingqu> </TD> </TR> </TBODY> </TABLE> </DIV> </DIV> str;echo $str;echo '<hr>';preg_match_all('/\<div style=\\\\\"([^\"]+)\\\\\" id=[^\>]+\>.*?\<div id=idH([^\s]+).+?\<input.+?name=([^\s\>]+).*?\>.+?\<\/div\>.*?\<\/div\>/is', $str, $matches);print_r($matches); 谢谢楼上的回复,你的这个正则不太好用哦,得不到结果哦只有个空数组Array( [0] => Array ( ) [1] => Array ( ) [2] => Array ( ) [3] => Array ( ) ) 这个问题我已经解决了,2楼的代码是正确的,问题出在浏览器版本上面id6,7,8输出的html数据流居然是不同的,所有贪婪匹配会因为不同的浏览器而失效,id6输出顺序是<div class=XXX id=XXX style=XXXie8输出顺序是<div style=XXX id=XXX 有兴趣研究版本兼容性的朋友,不妨试试目前是用的抓取元素的方式解决的,把代码发上来,有兴趣的哥们看看$str=$_POST["htmlcode"];$str=str_replace("\\","",$str);preg_match_all('/style=\"([^"]*)/is',$str,$arrPos);preg_match_all('/idDrag([^\s>]+)/is',$str,$arrIds);preg_match_all('/name=([^\s>]+)/is',$str,$arrNames); 请问在一PHP文件中引用另一PHP文件中的<form>有效吗 PHP查询数据库出错、 fckeditor报错 不能建立文件夹,大家帮帮忙! PHP写的server端,如何接收手机客户端传来的json数据 php 得到指定字符串 请教php中的session和变量是一个东西吗? 数据库操作安全性问题 请教数据库问题!!!! 关于PHP的请求帮助! 求大神帮忙 每年遍历一次 名单 的实现 session 问题
$str = <<<str
<DIV style=\"POSITION: absolute; TOP: 19px; LEFT: 25px\" id=idDrag485 class=idfrom ondblclick=deldiv(485)>
<DIV id=idHandle485 class=idtest ondblclick=deldiv(485)>
<TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\">
<TBODY> <TR> <TD width=\"30%\" align=right>联系人: </TD> <TD width=\"70%\"> <INPUT class=red size=20 name=relname {Require} style="color:#000000;"> </TD> </TR> </TBODY> </TABLE>
</DIV>
</DIV> <DIV style=\"POSITION: absolute; TOP: 193px; LEFT: 53px\" id=idDrag267 class=idfrom ondblclick=deldiv(267)>
<DIV id=idHandle267 class=idtest ondblclick=deldiv(267)>
<TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\">
<TBODY> <TR> <TD width=\"30%\" align=right>性别: </TD> <TD width=\"70%\"> <INPUT class=black value={Require} type=radio name=sex> </TD> </TR> </TBODY> </TABLE>
</DIV>
</DIV> <DIV style=\"POSITION: absolute; TOP: 70px; LEFT: 24px\" id=idDrag456 class=idfrom ondblclick=deldiv(456)>
<DIV id=idHandle456 class=idtest ondblclick=deldiv(456)>
<TABLE class=control_contect_li cellSpacing=0 cellPadding=0 width=\"100%\">
<TBODY> <TR> <TD width=\"30%\" align=right>兴趣: </TD> <TD width=\"70%\"> <INPUT class=blue value={Require} type=checkbox name=xingqu> </TD> </TR> </TBODY> </TABLE>
</DIV>
</DIV>
str;echo $str;
echo '<hr>';preg_match_all('/\<div style=\\\\\"([^\"]+)\\\\\" id=[^\>]+\>.*?\<div id=idH([^\s]+).+?\<input.+?name=([^\s\>]+).*?\>.+?\<\/div\>.*?\<\/div\>/is', $str, $matches);print_r($matches);
只有个空数组
Array
(
[0] => Array
(
)
[1] => Array
(
)
[2] => Array
(
)
[3] => Array
(
)
)
id6输出顺序是<div class=XXX id=XXX style=XXX
ie8输出顺序是<div style=XXX id=XXX
有兴趣研究版本兼容性的朋友,不妨试试
目前是用的抓取元素的方式解决的,把代码发上来,有兴趣的哥们看看
$str=$_POST["htmlcode"];
$str=str_replace("\\","",$str);
preg_match_all('/style=\"([^"]*)/is',$str,$arrPos);
preg_match_all('/idDrag([^\s>]+)/is',$str,$arrIds);
preg_match_all('/name=([^\s>]+)/is',$str,$arrNames);