本文操作环境:windows7系统、php7.1版,dell g3电脑
php怎么修改html文件内容?
代码如下:
<?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视频教程》
以上就是php怎么修改html文件内容的详细内容。
