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

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

WBOY
WBOY원래의
2016-06-23 13:10:58949검색

        $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);
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.