我正在使用AJAX调用一个PHP文件,它将有效地编辑另一个HTML文件中的特定内容。我的问题是,我不确定针对这些特定领域的最佳方式。
我认为需要将某种唯一标识符附加到需要编辑的标记或注释中,然后PHP在进行替换之前简单地搜索它?
发布于 2012-02-07 23:04:10
为此,请使用simplehtml。
您可以像这样将所有<h1>更改为foo:
$html = file_get_html('http://www.google.com/');
foreach($html->find('h1') as $element)
{
$element->innertext = 'foo';
}
echo $html;发布于 2012-02-07 23:00:11
simplehtmldom框架允许您搜索和修改HTML文件或url的DOM。
http://simplehtmldom.sourceforge.net/
// Create DOM from URL or file $html =
file_get_html('http://www.google.com/');
// Find all images foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links foreach($html->find('a') as $element)
echo $element->href . '<br>';另一个很好的库是querypath路径。它非常类似于jquery:
qp($html_code)->find('body')->text('Hello World')->writeHTML();https://stackoverflow.com/questions/9178424
复制相似问题