简体   繁体   English

SimpleHtmlDom编辑并保存文件

[英]SimpleHtmlDom Edit and Save file

http://simplehtmldom.sourceforge.net/ http://simplehtmldom.sourceforge.net/

Looking to parse through an HTML file, make some small changes, and overwrite the current file with the updates. 试图解析HTML文件,进行一些小的更改,然后使用更新覆盖当前文件。 Was wondering if this was possible through simplehtmldom 想知道是否可以通过simplehtmldom实现

As of right now, I can access everything, but have no way of displaying the entirely of the HTML With all of the changes included. 到目前为止,我可以访问所有内容,但是无法显示包含所有更改的全部HTML内容。 Is it only possible to grab specific values? 只能获取特定的值吗?

If so, what other methods could I use to accomplish this? 如果是这样,我还可以使用什么其他方法来完成此任务? I'm afraid the environment I have to work in is extremely limited due to security issues. 恐怕由于安全问题,我必须工作的环境非常有限。

The simplehtmldom object can be used as a string, and will just contain the full contents of the modified document. simplehtmldom对象可以用作字符串,并且仅包含修改后的文档的全部内容。

For example: 例如:

echo($html);
file_put_contents($filename, $html);

If you prefer an object-oriented method, you can use save() : 如果您喜欢面向对象的方法,可以使用save()

$updated = $html->save();

or 要么

$html->save($filename);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM