Home  >  Article  >  Backend Development  >  求一个正责表达式,我写的不知道为啥不行 打印$d 里包含<dd[^>]*>([sS]*)</dd>之间的类容

求一个正责表达式,我写的不知道为啥不行 打印$d 里包含<dd[^>]*>([sS]*)</dd>之间的类容

WBOY
WBOYOriginal
2016-06-23 13:10:58923browse

        $a = '<dl class="info_l">                    <dd class="__r_c_" pan="M14_Movie_Overview_BaseInfo"><strong>导演:</strong>                        <a href="http://people.mtime.com/1654943/" target="_blank" rel="v:directedBy">杨庆</a>                    </dd>                    <dd  class="__r_c_" pan="M14_Movie_Overview_BaseInfo"><strong>编剧:</strong>                        <a href="http://people.mtime.com/1654943/" target="_blank">杨庆</a>                    </dd>                    <dd  class="__r_c_" pan="M14_Movie_Overview_BaseInfo">                        <strong>国家地区:</strong>                            <a href="http://movie.mtime.com/movie/search/section/?nation=China" target="_blank">中国</a>                    </dd>                  <dd  class="__r_c_" pan="M14_Movie_Overview_BaseInfo">                    <strong>发行公司:</strong>                    <a href="http://movie.mtime.com/company/121271/" target="_blank">五洲电影发行有限公司</a>                    <a href="http://movie.mtime.com/229813/details.html#company" target="_blank">...</a>                  </dd>                    <dt class="__r_c_" pan="M14_Movie_Overview_PlotsSummary">                        <h4 class="px14 mt12">                            剧情:</h4>                        <p class="mt6 lh18">在布满防空洞的重庆,三个从初中就“厮混”在一起的好兄弟合伙开着一家火锅店,名为“老同学洞子火锅”。由于经营不善,几人落得只能转让店铺还债。为了店铺能“卖个好价钱”,三人打起了“扩充门面”的主意,自行往洞里开挖。没想到,..</p>                            <p class="tr mt9"><a href="http://movie.mtime.com/229813/plots.html">更多剧情 <i class="gt"></i></a></p>                    </dt>            </dl>';        preg_match_all("<dd[^>]*>([\s\S]*)<\/dd>/isU",$a,$d);        print_r($d);


回复讨论(解决方案)

preg_match_all("/<dd[^>]*>([\s\S]*?)<\/dd>/is",$a,$d);

正则没问题,只是少了起始分割符
preg_match_all(" /

]*>([\s\S]*)/isU",$a,$d);

$a = '<dl class="info_l">                    <dd class="__r_c_" pan="M14_Movie_Overview_BaseInfo"><strong>导演:</strong>                        <a href="http://people.mtime.com/1654943/" target="_blank" rel="v:directedBy">杨庆</a>                    </dd>                    <dd  class="__r_c_" pan="M14_Movie_Overview_BaseInfo"><strong>编剧:</strong>                        <a href="http://people.mtime.com/1654943/" target="_blank">杨庆</a>                    </dd>                    <dd  class="__r_c_" pan="M14_Movie_Overview_BaseInfo">                        <strong>国家地区:</strong>                            <a href="http://movie.mtime.com/movie/search/section/?nation=China" target="_blank">中国</a>                    </dd>                  <dd  class="__r_c_" pan="M14_Movie_Overview_BaseInfo">                    <strong>发行公司:</strong>                    <a href="http://movie.mtime.com/company/121271/" target="_blank">五洲电影发行有限公司</a>                    <a href="http://movie.mtime.com/229813/details.html#company" target="_blank">...</a>                  </dd>                    <dt class="__r_c_" pan="M14_Movie_Overview_PlotsSummary">                        <h4 class="px14 mt12">                            剧情:</h4>                        <p class="mt6 lh18">在布满防空洞的重庆,三个从初中就“厮混”在一起的好兄弟合伙开着一家火锅店,名为“老同学洞子火锅”。由于经营不善,几人落得只能转让店铺还债。为了店铺能“卖个好价钱”,三人打起了“扩充门面”的主意,自行往洞里开挖。没想到,..</p>                            <p class="tr mt9"><a href="http://movie.mtime.com/229813/plots.html">更多剧情 <i class="gt"></i></a></p>                    </dt>            </dl>';        preg_match_all("/<dd[^>]*>([\s\S]*)<\/dd>/isU",$a,$d);         print_r($d[1]);
Array(    [0] => <strong>导演:</strong>                        <a href="http://people.mtime.com/1654943/" target="_blank" rel="v:directedBy">杨庆</a>                        [1] => <strong>编剧:</strong>                        <a href="http://people.mtime.com/1654943/" target="_blank">杨庆</a>                        [2] =>                         <strong>国家地区:</strong>                            <a href="http://movie.mtime.com/movie/search/section/?nation=China" target="_blank">中国</a>                        [3] =>                     <strong>发行公司:</strong>                    <a href="http://movie.mtime.com/company/121271/" target="_blank">五洲电影发行有限公司</a>                    <a href="http://movie.mtime.com/229813/details.html#company" target="_blank">...</a>                  )
preg_match_all("/

]*>([\s\S]*)/isU",$a,$d);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn