全文搜索和替換
更新時(shí)間:2006年10月09日 00:00:00 作者:
<?php
exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode);
if ($errorCode){
if ($errorCode == 1){
echo "Possibly no files were found with $oldword in them<BR>\n";
}
echo "OS Error: $errorCode<BR>\n";
echo "Check 'man errno' and count down<BR>\n";
echo "Usually paths/permissions<BR>\n";
}
while (list(,$path) = each($results)){
$parts = explode(':', $path);
$path = $parts[0];
$fp = fopen($path, 'r') or print("Cannot read $path<BR>\n");
if ($fp){
$data = fread($fp, filesize($path));
fclose($fp);
$newdata = str_replace($oldword, $newword, $data);
$fp = fopen($path, 'w') or print("Cannot write $path<BR>\n");
if ($fp){
fwrite($fp, $newdata);
fclose($fp);
echo $path, "<BR>\n";
}
}
}
?>
Example
http://yourserver.com/globalreplace.php?oldword=test&newword=text&rootpath=/path/to/dir
exec("/bin/grep -r '$oldword' $rootpath", $results, $errorCode);
if ($errorCode){
if ($errorCode == 1){
echo "Possibly no files were found with $oldword in them<BR>\n";
}
echo "OS Error: $errorCode<BR>\n";
echo "Check 'man errno' and count down<BR>\n";
echo "Usually paths/permissions<BR>\n";
}
while (list(,$path) = each($results)){
$parts = explode(':', $path);
$path = $parts[0];
$fp = fopen($path, 'r') or print("Cannot read $path<BR>\n");
if ($fp){
$data = fread($fp, filesize($path));
fclose($fp);
$newdata = str_replace($oldword, $newword, $data);
$fp = fopen($path, 'w') or print("Cannot write $path<BR>\n");
if ($fp){
fwrite($fp, $newdata);
fclose($fp);
echo $path, "<BR>\n";
}
}
}
?>
Example
http://yourserver.com/globalreplace.php?oldword=test&newword=text&rootpath=/path/to/dir
相關(guān)文章
php 之 沒(méi)有mysql支持時(shí)的替代方案
php 之 沒(méi)有mysql支持時(shí)的替代方案...2006-10-10vBulletin Forum 2.3.xx SQL Injection
vBulletin Forum 2.3.xx SQL Injection...2006-10-10一周讓你學(xué)會(huì)PHP 不錯(cuò)的學(xué)習(xí)資料
強(qiáng)烈推薦臺(tái)灣中原大學(xué)的php教程。 詼諧幽默,那絕對(duì)是大陸的教程沒(méi)法比的。2009-02-02將OICQ數(shù)據(jù)轉(zhuǎn)成MYSQL數(shù)據(jù)
將OICQ數(shù)據(jù)轉(zhuǎn)成MYSQL數(shù)據(jù)...2006-10-10用PHP動(dòng)態(tài)創(chuàng)建Flash動(dòng)畫(huà)
用PHP動(dòng)態(tài)創(chuàng)建Flash動(dòng)畫(huà)...2006-10-10PHP文件注釋標(biāo)記及規(guī)范小結(jié)
PHP文件注釋標(biāo)記及規(guī)范小結(jié),php開(kāi)發(fā)的朋友可以收藏下,方便以后使用,讓我們的代碼更專業(yè)2012-04-04WINDOWS下php5.2.4+mysql6.0+apache2.2.4+ZendOptimizer-3.3.0配置
WINDOWS下php5.2.4+mysql6.0+apache2.2.4+ZendOptimizer-3.3.0配置 與其他基本版本安裝相同! 第一: 裝http服務(wù)器apache2008-03-03