我想通過調用函數來替換php文件中的特定字符串。 我的一切至今是:用PHP處理PHP文件
function change_data($data1, $data2)
{
//Read php file in $result
$result= str_replace("tag1", $data1, $result);
$result= str_replace("tag2", $data2, $result);
//Save php file
}
你能幫助我,並加以儲存,這樣沒有人可以訪問該文件?
編輯:我試過如下:在文件中
function change_data($data1, $data2)
{
$file = 'test.php';
$result = file_get_contents($file);
//Replace initial with test
$result = str_replace("intial", "test", $result);
file_put_contents($file, $result);
}
沒有什麼變化。
這似乎不適用於我,我編輯了我的問題以顯示我做了什麼 –