Home > Backend Development > PHP Tutorial > 求一段正则表达式!

求一段正则表达式!

WBOY
Release: 2016-06-23 14:26:58
Original
912 people have browsed it


  • xxx

  • xxx

  • xxx



  • xxx

  • xxx

  • xxx



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

/
    .*?(.*?).*?/is  只能匹配到第一个li里的内容

    回复讨论(解决方案)

    $s=<<<html<ul id="a"><li style="display:none">xxx</li><li style="display:block">xxx</li><li>xxx</li></ul><ul id="b"><li style="display:none">xxx</li><li style="display:block">xxx</li><li>xxx</li></ul>html;preg_match('#<ul id="b">(.+)</ul>#is',$s,$m);preg_match_all('#<li[^>]*>(.+)</li>#isU',$m[1],$arr);print_r($arr[1]);
    Copy after login

    不分两次行么?

    能力有限,看其他高手有妙招不。

    不能用jquery吗?
    $('#b')->find('ul')->find('li')就是你想要的内容了。

    (?(?:\s*

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