Home >Backend Development >PHP Tutorial >求一段正则表达式!解决方法

求一段正则表达式!解决方法

WBOY
WBOYOriginal
2016-06-13 11:47:41991browse

求一段正则表达式!


  • xxx

  • xxx

  • xxx



  • xxx

  • xxx

  • xxx



我想正则取得ID为b的UL里的每一个li里的内容,正则应该怎么写?

/
    .*?(.*?).*?/is  只能匹配到第一个li里的内容
    ------解决方案--------------------
    $s=<<<html<br /><ul id="a"><br /><li style="display:none">xxx</li><br /><li style="display:block">xxx</li><br /><li>xxx</li><br /></ul><br /><ul id="b"><br /><li style="display:none">xxx</li><br /><li style="display:block">xxx</li><br /><li>xxx</li><br /></ul><br />html;<br /><br />preg_match('#<ul id="b">(.+)</ul>#is',$s,$m);<br />preg_match_all('#<li[^>]*>(.+)</li>#isU',$m[1],$arr);<br />print_r($arr[1]);

    ------解决方案--------------------
    (?(?:\s*.*?\s*)*)\s*(.*?)\s*  给你个参考,你自己根据需求再修改下
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