求高手解决正则表达式问题

younet 2006-07-21 06:30:06
<td class="ebcBid"><a href="/_W0QQfsooZ2QQfsopZ14QQsatitleZQe7QacQ94Qe8QaeQb0Qe6Q9cQacQe7Q94Qb5Qe8Q84Q91QQsbrsrtZl">出价数</a></td><td class="ebcLReg"><a href="/_W0QQfsooZ1QQfsopZ24QQsatitleZQe7QacQ94Qe8QaeQb0Qe6Q9cQacQe7Q94Qb5Qe8Q84Q91QQsbrsrtZl">地区</a></td><td class="ebcTim hl"><a href="/_W0QQfsooZ2QQfsopZ2QQsatitleZQe7QacQ94Qe8QaeQb0Qe6Q9cQacQe7Q94Qb5Qe8Q84Q91QQsbrsrtZl">剩余时间 </a> <img src="http://pics.ebaystatic.com/aw/pics/sort_up.gif" width="9" height="5" alt="" /></td><td class="ebcBid"><img border="0" title="一口价" alt="一口价" src="http://pics.ebaystatic.com/aw/pics/cn/bin_15x54.gif" align="middle" class="binImg" /></td><td class="ebcLReg">辽宁-其它城市</td><td class="ebcTim">1小时 41分钟</td><td class="ebRight"> </td><td class="ebcBid">-<br /><img border="0" title="一口价" alt="一口价" src="http://pics.ebaystatic.com/aw/pics/cn/bin_15x54.gif" align="middle" class="binImg" /></td><td class="ebcLReg">上海</td><td class="ebcTim"><span class="error">32分钟</span></td><td class="ebRight"> </td>

我现在想得到
<img border="0" title="一口价" alt="一口价" src="http://pics.ebaystatic.com/aw/pics/cn/bin_15x54.gif" align="middle" class="binImg" />

我的代码是
$regExt = "/<td class=\"ebcBid\">[\-<br \/>]*(.+)<\/td>/iUs";
preg_match_all($regExt, $str, $eb, PREG_SET_ORDER);

但是问题来了,我得到了一个错误结果
<a href="/_W0QQfsooZ2QQfsopZ14QQsatitleZQe7QacQ94Qe8QaeQb0Qe6Q9cQacQe7Q94Qb5Qe8Q84Q91QQsbrsrtZl">出价数</a>


我如何才能过滤掉这个错误结果
...全文
149 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zeroleonhart 2006-07-23
  • 打赏
  • 举报
回复
preg_match_all('/<td\sclass="ebcBid">(?:.*?)(<img\sborder.+?\/>)<\/td>/is',$str,$ar);
print_r($ar);
younet 2006-07-23
  • 打赏
  • 举报
回复
preg_match_all($regExt, $str, $eb, PREG_SET_ORDER);
我用了preg_match_all这个函数,很显然是要得到所有符合条件的结果
younet 2006-07-22
  • 打赏
  • 举报
回复
问题没有这么简单啊, 还有一个这样的字符串 -<br /> 在<img 前面
zeroleonhart 2006-07-22
  • 打赏
  • 举报
回复
there are two img tags in the string,and I think you only need to get the first one,do you?
zeroleonhart 2006-07-21
  • 打赏
  • 举报
回复
$str='<td class="ebcBid"><a href="/_W0QQfsooZ2QQfsopZ14QQsatitleZQe7QacQ94Qe8QaeQb0Qe6Q9cQacQe7Q94Qb5Qe8Q84Q91QQsbrsrtZl">出价数</a></td><td class="ebcLReg"><a href="/_W0QQfsooZ1QQfsopZ24QQsatitleZQe7QacQ94Qe8QaeQb0Qe6Q9cQacQe7Q94Qb5Qe8Q84Q91QQsbrsrtZl">地区</a></td><td class="ebcTim hl"><a href="/_W0QQfsooZ2QQfsopZ2QQsatitleZQe7QacQ94Qe8QaeQb0Qe6Q9cQacQe7Q94Qb5Qe8Q84Q91QQsbrsrtZl">剩余时间 </a> <img src="http://pics.ebaystatic.com/aw/pics/sort_up.gif" width="9" height="5" alt="" /></td><td class="ebcBid"><img border="0" title="一口价" alt="一口价" src="http://pics.ebaystatic.com/aw/pics/cn/bin_15x54.gif" align="middle" class="binImg" /></td><td class="ebcLReg">辽宁-其它城市</td><td class="ebcTim">1小时 41分钟</td><td class="ebRight"> </td><td class="ebcBid">-<br /><img border="0" title="一口价" alt="一口价" src="http://pics.ebaystatic.com/aw/pics/cn/bin_15x54.gif" align="middle" class="binImg" /></td><td class="ebcLReg">上海</td><td class="ebcTim"><span class="error">32分钟</span></td><td class="ebRight"> </td>';


preg_match('/<td\sclass="ebcBid">(<img.+?\/>)<\/td>/is',$str,$ar);
echo $ar[1];

21,889

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧