用新函数替换许多php文件中不推荐使用的函数

问题描述:

我用这个函数----> 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重构功能? –

这段代码可以帮助你!

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)); 
    }