-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