我把r換成了r+,把w換成w+.
$file_name = './inc/const.php'; //要替換操作的文件
@$fp = fopen($file_name,'r+'); //打開要替換的文件
@$conf_file = fread($fp,filesize($file_name));
$conf_file = preg_replace("/httpurl\s*\=\s(\'|")(.*?)("|')/","httpurl = "" . $httpurl. """,$conf_file);
$conf_file = preg_replace("/databasePrefixs*=s('|\")(.*?)(\"|')/","databasePrefix = \"" . $databasePrefix. "\"",$conf_file);
fclose(@$fp);
@$fp = fopen($file_name,'w+');
$fw = fwrite($fp, trim($conf_file));
fclose($fp);
這樣應該可以,否則把@去掉.