How to solve the problem of preg_match_all crawling?

Source: Internet
Author: User
About the capture of preg_match_all & lt; div & gt; & lt; h1 & gt; title 1 & lt; h1 & gt; & lt; p & gt; content 1 & lt; p & gt; & lt; p & gt; content 2 & lt; p & gt; & lt; h1 & gt; title 2 & lt; h1 & gt; & lt; p & gt; content 1 & lt; p & gt; content 2 & lt; p & gt; & lt; p capture of preg_match_all


Title 1

Content 1


Content 2


Title 2

Content 1


Content 2


Content 3


Content 4


Title 3

Content 1


Content 2


Content 3




I want to use preg_match_all () to cyclically retrieve the content from the next
Title 1

Content 1


Content 2


------------
Title 2

Content 1


Content 2


Content 3


Content 4


------------
Title 3

Content 1


Content 2


Content 3



I thought about using
preg_match_all('/[\w\W]*<(h1|\/p)/U',$html, $out)

However, this will skip the next step, because the second one has been used by the first one.


------ Solution --------------------
preg_match_all('/

(.*)<\/p>/is', $str, $m);
$m = explode('', substr($m[1][0], 5));
foreach($m as $x)
echo htmlspecialchars ("$x") . '
';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.