<?php
$a=fopen(dirname(__FILE__)."/index.php","w");
echo dirname(__FILE__)."/index.php";
str_replace("你好","helllo",$a);
fclose($a);
<?php
//$a=fopen(dirname(__FILE__)."/index.php","w");
$a = dirname(__FILE__)."/index.php";
file_put_contents($a,str_replace('你好','helllo',file_get_contents($a)));
//fclose($a);
帮你稍微改了一下,清空了是因为你只是打开了文件并没有读取文件里的内容哈。
效果:
fopen的打开模式是w
,这会清空文件内容,应该使用a
( append)模式。
而且str_replace
函数不是这么用的吧
fopen打开的文件句柄,用fread、fgets才能得到内容,再用str_replace