-1
http://php.net/manual/en/tidy.body.php将返回使用<body>
标记包裹的身体内容。如何在没有<body>
标签的情况下获得正文内容?我想出了一些可能的解决方案,但是,它们并不是很优雅。使用整洁获取没有标签的身体
$tidy = new tidy;
$tidy->parseString($html);
$tidy->cleanRepair();
$body_content=trim(ltrim(rtrim(trim($tidy->body()->value),'</body>'),'<body>'));
var_dump($body_content);
$body=$tidy->body()->value;
$body_content=substr($body,7,strlen($body)-16);
var_dump($body_content);
感谢彼得,你的方法更优雅,但也许我会坚持我的黑客,因为它可能更快。 – user1032531