求一正则表达式

weijiepeng 2009-11-17 06:09:19
<div class="quote" style=""><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td width="24%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html"><img src="http://www.xx.com.cn/images/upfiles/qbs/20090624153330.jpg" bgcolor="eaeaea" height="120" width="120"></a> </td>
<td style="padding-top: 15px;" valign="top" width="76%"><a href="http://www.xx.com.cn/qbs/shop_4150.html">
<span style="font-size: 12px; color: rgb(102, 102, 102); font-weight: 100;">商家口碑: </span></td>
</tr>
</tbody></table></div>
<br>sss[attachimg]1213208[/attachimg][attachimg]1213208[/attachimg][attachimg]1213208[/attachimg]<br>************************<div></div>
得到有颜色的部分
...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wcqqq 2009-11-18
  • 打赏
  • 举报
回复
<?php

$str = <<<HTML
<div class="quote" style=""> <table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody> <tr>
<td width="24%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html"> <img src="http://www.xx.com.cn/images/upfiles/qbs/20090624153330.jpg" bgcolor="eaeaea" height="120" width="120"> </a> </td>
<td style="padding-top: 15px;" valign="top" width="76%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html">
<span style="font-size: 12px; color: rgb(102, 102, 102); font-weight: 100;">商家口碑: </span> </td>
</tr>
</tbody> </table> </div> <br>sss[attachimg]1213208[/attachimg][attachimg]1213208[/attachimg][attachimg]1213208[/attachimg] <br>************************ <div> </div>
<div class="quote" style=""> <table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody> <tr>
<td width="24%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html"> <img src="http://www.xx.com.cn/images/upfiles/qbs/20090624153330.jpg" bgcolor="eaeaea" height="120" width="120"> </a> </td>
<td style="padding-top: 15px;" valign="top" width="76%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html">
<span style="font-size: 12px; color: rgb(102, 102, 102); font-weight: 100;">商家口碑: </span> </td>
</tr>
</tbody> </table> </div> <br>sss[attachimg]1213208[/attachimg][attachimg]1213208[/attachimg][attachimg]1213208[/attachimg] <br>************************ <div> </div>
<div class="quote" style=""> <table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody> <tr>
<td width="24%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html"> <img src="http://www.xx.com.cn/images/upfiles/qbs/20090624153330.jpg" bgcolor="eaeaea" height="120" width="120"> </a> </td>
<td style="padding-top: 15px;" valign="top" width="76%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html">
<span style="font-size: 12px; color: rgb(102, 102, 102); font-weight: 100;">商家口碑: </span> </td>
</tr>
</tbody> </table> </div> <br>sss[attachimg]1213208[/attachimg][attachimg]1213208[/attachimg][attachimg]1213208[/attachimg] <br>************************ <div> </div>
HTML;

echo htmlspecialchars($str);

echo '<hr>';

preg_match_all('/(<div[^<]*?)(<table[^`]*?table>)([^>]*?div>)/i' , $str , $ary);

echo '<pre>';

print_r($ary);

echo "</pre>";

?>
weijiepeng 2009-11-18
  • 打赏
  • 举报
回复
得到这个div后面的值
weijiepeng 2009-11-18
  • 打赏
  • 举报
回复
匹配这个div了<div class="quote" style=""> 这个div有可能没有,有就匹配,没有就取不到值
阿_布 2009-11-18
  • 打赏
  • 举报
回复

$str =<<<html
<div class="quote" style=""> <table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody> <tr>
<td width="24%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html"> <img src="http://www.xx.com.cn/images/upfiles/qbs/20090624153330.jpg" bgcolor="eaeaea" height="120" width="120"> </a> </td>
<td style="padding-top: 15px;" valign="top" width="76%"> <a href="http://www.xx.com.cn/qbs/shop_4150.html">
<span style="font-size: 12px; color: rgb(102, 102, 102); font-weight: 100;">商家口碑: </span> </td>
</tr>
</tbody> </table> </div> <br>sss[attachimg]1213208[/attachimg][attachimg]1213208[/attachimg][attachimg]1213208[/attachimg] <br>************************ <div> </div>
html;
preg_match_all("/^(.+?)(<br>)/s",$str,$out);
echo $out[1][0];
阿_布 2009-11-17
  • 打赏
  • 举报
回复

preg_match_all("/^(.*?)(?=<br>)/",$str,$out);
echo $out[1][0];

21,886

社区成员

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

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