php修改html文件内容并保存 急急急

php修改html文件内容并保存 急急急,第1张

<?php

$file_content = file_get_contents('1.html')

$qiqi=str_replace("abc" , "000" ,$file_content)

$filename = '1.html'

$somecontent = $qiqi

// 首先我们要确定文件存在并且可写。

if (is_writable($filename)) {

// 在这个例子里,我们将使用添加模式打开$filename,

// 因此,文件指针将会在文件的开头,

// 那就是当我们使用fwrite()的时候,$somecontent将要写入的地方。

if (!$handle = fopen($filename, 'w')) {

echo "不能打开文件 $filename"

exit

}

// 将$somecontent写入到我们打开的文件中。

if (fwrite($handle, $somecontent) === FALSE) {

echo "不能写入到文件 $filename"

exit

}

echo "成功地将 $somecontent 写入到文件$filename"

fclose($handle)

} else {

echo "文件 $filename 不可写"

}

?>

把分给我吧,上面程序调试可以实现你的要求,我写了半天呢!

用法示例:

<?php

// example of how to use basic selector to retrieve HTML contents

include('../simple_html_dom.php')

// get DOM from URL or file

$html = file_get_html('http://www.google.com/')

// find all link

foreach($html->find('a') as $e)

echo $e->href . '<br>'

// find all image

foreach($html->find('img') as $e)

echo $e->src . '<br>'

// find all image with full tag

foreach($html->find('img') as $e)

echo $e->outertext . '<br>'

// find all div tags with id=gbar

foreach($html->find('div#gbar') as $e)

echo $e->innertext . '<br>'

// find all span tags with class=gb1

foreach($html->find('span.gb1') as $e)

echo $e->outertext . '<br>'

// find all td tags with attribite align=center

foreach($html->find('td[align=center]') as $e)

echo $e->innertext . '<br>'

// extract text from table

echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>'

// extract text from HTML

echo $html->plaintext

?>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7133418.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-02
下一篇 2023-04-02

发表评论

登录后才能评论

评论列表(0条)

保存