dongxiao1591 2017-02-16 06:56
浏览 40

preg_match两个html标签的结尾

I try to preg_match the end of two html tags

<span class="a"> 
   <span>123</span> 
   <span>456</span></span>
<span class="b">
    <span>789</span>
....

I want to get the content of class a (123 456) and try this pattern

preg_match('#<span\sclass="a">(.*?)</span></span>#')

but I just get the first span (123).

How can I end the pattern in </span></span>

  • 写回答

1条回答 默认 最新

  • doushanmo7024 2017-02-17 18:14
    关注

    <span class="a">([\W\w]*?)<\/span><\/span>

    The dot . only looks for non-newline characters, which means it would never get past the first line (in theory).

    评论

报告相同问题?