I want to match the first few paragraphs from html code and I have this code so far:
$page_contents = '<html><body><p style="asdas" class="asd asdas">lorem ipsum 1</p><p>lorem ipsum 2</p><br></body></html>';
preg_match_all('/\<p(?:[^>]*)?>(.*)<\/p>/is', $page_contents, $paragraphs_matches);
print_r($paragraphs_matches);
and it matches this:
lorem ipsum 1</p><p>lorem ipsum 2
how to modify it so it matches this ?:
lorem ipsum 1
lorem ipsum 2
to the last one found. To make it nongreedy use `?` -> `.*` - greedy, `.*?` - nongreedy (will match for as little characters as possible). Docs: http://docstore.mik.ua/orelly/webprog/pcook/ch13_05.htm
– Viliam Aboši Apr 18 '17 at 19:49]*)?>(.*?)<\/p>/i'` thank you.
– adrianTNT Apr 18 '17 at 19:51