PHP Simple HTML DOM Parser - <body> 仅重命名 div ID



我正在使用PHP简单的HTML DOM解析器,通过这简单的代码来获得良好的效果:-

<?php
include_once('./simple_html_dom.php');
$oldhtml = file_get_html('./6.html');
$newhtml = $oldhtml->find("body", 0);
echo $newhtml->innertext;
$oldhtml->clear();
$newhtml->clear();
?>

(我很欣赏它目前的形式可以改进!

但是有一件事我需要改变,但我无法找出正确的语法来使其工作。生成的文档几乎完全适合我的需求,除了它以

<div id="container">

我想简单地将该ID重命名为其他名称。我可以忍受<div>或理想情况下像<div id "six">

任何指示将不胜感激。

试试这段代码:

include_once('simple_html_dom.php');
$oldhtml = file_get_html('http://stackoverflow.com/');
$oldhtml->find('div[id=custom-header]', 0)->id= 'six';
die($oldhtml);

最新更新