使用simple_html_dom操纵div内容

时间:2016-02-15 20:29:52

标签: php jquery simple-html-dom

test01.php

<div id="res"></div>

我需要更改服务器端#res的内容。

ajax.php

include ("simple_html_dom.php");  // the same folder as `ajax.php`
$url = $_POST["url"];  // http://localhost/up/matria/test01.php - that's ok
$html = file_get_html($url);
$html->find('div#res')->innertext = '525';

为了保存我尝试的更改:

$html->save($url);  // first try
file_put_contents($url, $html);  // next try
$htmlString = $html->save();
file_put_contents($url);  // next try

重新加载页面 - res仍为空。

1 个答案:

答案 0 :(得分:1)

更改innertext后,继续将html保存回文件

像:

$html->save(path to file on disk);

或者,您可以返回html字符串并使用PHP文件系统函数保存它:

$htmlString = $html->save();
file_put_contents(path to file on disk);
相关问题