<?php
$a=fopen(dirname(__FILE__)."/index.php","w");
echo dirname(__FILE__)."/index.php";
str_replace("你好","helllo",$a);
fclose($a);
str_replace替换目标文件内容,结果目标文件全被清空了,为什么
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
锅巴胸 2019-01-28 10:38关注<?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);帮你稍微改了一下,清空了是因为你只是打开了文件并没有读取文件里的内容哈。
效果:
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报