Home > Backend Development > PHP Tutorial > 一个简单的正则匹配问题

一个简单的正则匹配问题

WBOY
Release: 2016-06-23 14:24:57
Original
895 people have browsed it

<ul>					<li><a href="/wudongqiankun/" class="playpic"><img  src="/bookpic/3/3710.jpg" / alt="一个简单的正则匹配问题" ></a><p class="mov-title"><a href="/wudongqiankun/">武动乾坤</a></p></li><li><a href="/zhumataixingce/" class="playpic"><img  src="/bookpic/3/3709.jpg" / alt="一个简单的正则匹配问题" ></a><p class="mov-title"><a href="/zhumataixingce/">驻马太行侧</a></p></li><li><a href="/tianzhubian/" class="playpic"><img  src="/bookpic/3/3660.jpg" / alt="一个简单的正则匹配问题" ></a><p class="mov-title"><a href="/tianzhubian/">天珠变</a></p></li><li><a href="/tunshixingkong/" class="playpic"><img  src="/bookpic/3/3658.jpg" / alt="一个简单的正则匹配问题" ></a><p class="mov-title"><a href="/tunshixingkong/">吞噬星空</a></p></li>					</ul>					</ul>				</div>			</div><div class="book_texttable"><div class="book_texttitle">正文</div><div class="book_listtext">			<li><a href="/manghuangji/1448661/" target="_blank">第一章 地府</a></li><li><a href="/manghuangji/1448662/" target="_blank">第二章 投胎</a></li><li><a href="/manghuangji/1448663/" target="_blank">第三章 降生</a></li><li><a href="/manghuangji/1448664/" target="_blank">第四章 府主</a></li><li><a href="/manghuangji/1448746/" target="_blank">第五章 纪氏</a></li><li><a href="/manghuangji/1449087/" target="_blank">第六章 修仙路</a></li>
Copy after login






我要匹配
  • 第一章 地府
  • 这种的,也就是要匹配所有章节地址,但我写的是
  • (.*)

  • 结果匹配时也会把前面的
    <li><a href="/wudongqiankun/" class="playpic"><img  src="/bookpic/3/3710.jpg" / alt="一个简单的正则匹配问题" ></a><p class="mov-title"><a href="/wudongqiankun/">武动乾坤</a></p></li><li><a href="/zhumataixingce/" class="playpic"><img  src="/bookpic/3/3709.jpg" / alt="一个简单的正则匹配问题" ></a><p class="mov-title"><a href="/zhumataixingce/">驻马太行侧</a></p></li><li><a href="/tianzhubian/" class="playpic"><img  src="/bookpic/3/3660.jpg" / alt="一个简单的正则匹配问题" ></a><p class="mov-title"><a href="/tianzhubian/">天珠变</a></p></li><li><a href="/tunshixingkong/" class="playpic"><img  src="/bookpic/3/3658.jpg" / alt="一个简单的正则匹配问题" ></a><p class="mov-title"><a href="/tunshixingkong/">吞噬星空
    Copy after login
    这段也匹配上了,这个怎么处理一下。


    回复讨论(解决方案)

    用测试工具试了,没问题,不知道楼主是怎么匹配的,最好发些代码出来

    preg_match_all('#<li><a href="([^"]+)" target="_blank">(.*)</a></li>#isU',$s,$m);print_r($m);
    Copy after login

    (.*)#U',$s,$m);    print_r($m);?>
    Copy after login
         楼主的也能用啊。。。

    source:php.cn
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template