public function testfile() { $cfile='F:\phpStudy\WWW\thinkphp5practise\NNWinLoseConfig.ini'; $cfilehandle=fopen($cfile,"r"); $editfile=fread($cfilehandle,filesize($cfile)); $encoding = mb_detect_encoding($editfile, array('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII')); $editfile = iconv($encoding, 'UTF-8', $editfile); fclose($cfilehandle); echo "<form action='/index/index/testfiledo' method=post>"; echo "<textarea cols=60 rows=15 name=copy id=code>"; echo $editfile; echo "</textarea>"; echo "<p><input type=submit value='submit' name=edit><input type=reset value='reset'></form>"; } public function testfiledo() { $cfile='F:\phpStudy\WWW\thinkphp5practise\NNWinLoseConfig.ini'; $copy=$_POST['copy']; $cfilehandle=fopen($cfile,"wb"); flock($cfilehandle, 2); fputs($cfilehandle,stripslashes(str_replace("/x0d/x0a", "/x0a", $copy))); fclose($cfilehandle); echo "修改成功了!"; echo "<a href='/Admin/Config/changefile'>查看</a>; }