BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / www-technology / #10658同步于 2010/8/14
该镜像源已超过 30 天没有更新,可能在源站已被删除。
WWWTechnology机器人发帖

求助正则表达

xsxtxt
2010/8/14镜像同步2 回复
比如如下一段html文件: <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b>unset</b></span> ( <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$var</tt></span> [, <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$var</tt></span> [, <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$...</tt></span> ]] )</div> 使用php想通过正则表达式提取出<div class="methodsynopsis dc-description"></div>之间的内容,请问该如何写正则表达式?谢谢!
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
BookMoth机器人#1 · 2010/8/14
<?php $str = '<div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b>unset</b></span> ( <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$var</tt></span> [, <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$var</tt></span> [, <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$...</tt></span> ]] )</div> '; $reg = '/<div class="methodsynopsis dc-description">(.*)<\/div>/s'; preg_match($reg,$str,$result); print_r($result); ?> $result结果是这样的: Array ( [0] => <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b>unset</b></span> ( <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$var</tt></span> [, <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$var</tt></span> [, <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$...</tt></span> ]] )</div> [1] => <span class="type"><span class="type void">void</span></span> <span class="methodname"><b>unset</b></span> ( <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$var</tt></span> [, <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$var</tt></span> [, <span class="methodparam"><span class="type"><a class="type mixed" href="language.pseudo-types.php#language.types.mixed">mixed</a></span> <tt class="parameter">$...</tt></span> ]] ) ) $result[1],貌似就是你需要的~ 【 在 xsxtxt 的大作中提到: 】 : 比如如下一段html文件: : <div class="methodsynopsis dc-description"> : <span class="type"><span class="type void">void</span></span> <span class="methodname"><b>unset</b></span> : ...................
xsxtxt机器人#2 · 2010/8/15
谢了,昨天写的时候正则表达式少写加了一个‘\’~ 【 在 BookMoth 的大作中提到: 】 : <?php : $str = '<div class="methodsynopsis dc-description"> : <span class="type"><span class="type void">void</span></span> <span class="methodname"><b>unset</b></span> : ...................