试试
PHP DOM*:
$html = '
some content
'; // put your cURL result here
$dom = new DOMDocument;
$dom->loadHtml($html);
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//comment()') as $comment) {
$comment->parentNode->removeChild($comment);
}
$body = $xpath->query('//body')->item(0);
$newHtml = $body instanceof DOMNode ? $dom->saveXml($body) : 'something failed';
var_dump($newHtml);
输出:
string(36) "
some content
"