我想匹配html代码中的前几段,到目前为止我已经有了这段代码:
$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);
它与此匹配:
lorem ipsum 1</p><p>lorem ipsum 2
如何修改它以使其匹配?:
lorem ipsum 1
lorem ipsum 2