2016-05-17 43 views
0

我用這個函數----> import_request_variables('p')在超過50個php文件中使用這個函數 - > extract($ _ GET,EXTR_PREFIX_ALL,' p');在那裏,PHP腳本可以做這個工作,而無需打開每個文件用新函數替換許多php文件中不推薦使用的函數

我想是這樣的:

//讀取整個字符串

$str=implode("",file('../*.php')); 
$fp=fopen('../*.php','w'); 
//replace something in the file string, here i am replacing import_request_variables('p') to extract($_GET, EXTR_PREFIX_ALL, 'p') 
$str=str_replace('import_request_variables('p')','extract($_GET, EXTR_PREFIX_ALL, 'p')',$str); 
//now, save the file 
fwrite($fp,$str,strlen($str)); 
+2

爲什麼不使用某些IDE重構功能? –

回答

0

這段代碼可以幫助你!

foreach (glob("path/to/files/*.php") as $filename) 
    { 
     $file = file_get_contents($filename); 
     file_put_contents($filename, str_replace("import_request_variables('p')","extract($_GET, EXTR_PREFIX_ALL",$file)); 
    } 
相關問題