Home > Backend Development > PHP Tutorial > php中正则无法匹配内容

php中正则无法匹配内容

WBOY
Release: 2016-06-06 20:06:14
Original
981 people have browsed it

<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>
Copy after login
'; $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>

Related labels:
php
source:php.cn
Previous article:mac - PHP安装扩展make install报错 Next article:怎么由一维数组生成多维数组
Statement of this Website
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
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template