How can I grab the entire content inside <body>
tag with regex?
For instance,
<html><body><p><a href="#">xx</a></p>
<p><a href="#">xx</a></p></body></html>
I want to return this only,
<p><a href="#">xx</a></p>
<p><a href="#">xx</a></p>
Or any other better ideas? maybe DOM but I have to use saveHTML();
then it will return doctype
and body
tag...
HTML Pu开发者_JS百科rifier is a pain to use so I decide not to use it. I thought regex could be the next best option for my disaster.
preg_match("/<body[^>]*>(.*?)<\/body>/is", $html, $matches);
$matches[1]
will be the contents of the body tag
preg_match("~<body.*?>(.*?)<\/body>~is", $html, $match);
print_r($match);
精彩评论