首页 >后端开发 >php教程 >php中正则无法匹配内容

php中正则无法匹配内容

WBOY
WBOY原创
2016-06-06 20:06:14956浏览

<code><?php $output = '
<div class=obssin>
                <div class="substatus">看过</div>
                
    <ul>
            <li class="aob">
                <a href="https://movie.douban.com/subject/3338862/" title="终结者:创世纪

终结者:创世纪 / 终结者5" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p2262649521.jpg" class="climg" alt="终结者:创世纪">
                </a>
            </li>
            <li class="aob">
                <a href="https://movie.douban.com/subject/1291844/" title="终结者2:审判日

终结者2:审判日 / 终结者2" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p1910909085.jpg" class="climg" alt="终结者2:审判日">
                </a>
            </li>
            <li class="aob">
                <a href="https://movie.douban.com/subject/1300656/" title="终结者

终结者 / 魔鬼终结者" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p511430453.jpg" class="climg" alt="终结者">
                </a>
            </li>
            <li class="aob">
                <a href="https://movie.douban.com/subject/24404677/" title="超体

超体 / LUCY:绝路煞姬(港)" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p2201909284.jpg" class="climg" alt="超体">
                </a>
            </li>
            <li class="aob">
                <a href="https://movie.douban.com/subject/25827963/" title="西游记之孙悟空三打白骨精

西游记之大闹天宫续集" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p2315805100.jpg" class="climg" alt="西游记之孙悟空三打白骨精">
                </a>
            </li>
    </ul>

            <div class="clear"></div>

    ';
    $output=preg_replace("/[\t\n\r]+/","",$output);
$partern='/<div class="obssin">
<div class="substatus">看过<ul><li class="aob"><a href="(%5B%5E<>%5D+)" title="([^<>]+)" target="_blank"><img src="(%5B%5E<>%5D+)" class="climg" alt="([^<>]+)">/';
preg_match_all($partern,$output,$result);
var_dump($result);   
?>
<p>这样为什么匹配不到内容?</p>

                            
                        


                                                                                                                        
                     <h2>回复内容:</h2>
                      
                                                            
<pre class="brush:php;toolbar:false"><code><?php $output = '
<div class=obssin>
                <div class="substatus">看过</div>
                
    <ul>
            <li class="aob">
                <a href="https://movie.douban.com/subject/3338862/" title="终结者:创世纪

终结者:创世纪 / 终结者5" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p2262649521.jpg" class="climg" alt="终结者:创世纪">
                </a>
            </li>
            <li class="aob">
                <a href="https://movie.douban.com/subject/1291844/" title="终结者2:审判日

终结者2:审判日 / 终结者2" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p1910909085.jpg" class="climg" alt="终结者2:审判日">
                </a>
            </li>
            <li class="aob">
                <a href="https://movie.douban.com/subject/1300656/" title="终结者

终结者 / 魔鬼终结者" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p511430453.jpg" class="climg" alt="终结者">
                </a>
            </li>
            <li class="aob">
                <a href="https://movie.douban.com/subject/24404677/" title="超体

超体 / LUCY:绝路煞姬(港)" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p2201909284.jpg" class="climg" alt="超体">
                </a>
            </li>
            <li class="aob">
                <a href="https://movie.douban.com/subject/25827963/" title="西游记之孙悟空三打白骨精

西游记之大闹天宫续集" target="_blank">
                    <img src="https://img3.doubanio.com/view/movie_poster_cover/ipst/public/p2315805100.jpg" class="climg" alt="西游记之孙悟空三打白骨精">
                </a>
            </li>
    </ul>

            <div class="clear"></div></code>
'; $output=preg_replace("/[\t\n\r]+/","",$output); $partern='/

改为:$partern='/<div class="obssin"><div class="substatus">看过<ul><li class="aob"><a href="(%5B%5E<>%5D+)" title="([^<>]+)" target="_blank"><img src="(%5B%5E<>%5D+)" class="climg" alt="([^<>]+)">/'; <p>PS:不建议这样用正则</p> </a></li></ul> </div></div>

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
上一篇:mac - PHP安装扩展make install报错下一篇:怎么由一维数组生成多维数组

相关文章

查看更多