全文搜索和替换
来源:互联网 发布:紧身衣尺码选择知乎 编辑:程序博客网 时间:2024/06/11 01:05
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
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
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<?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
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 全文搜索和替换
- 数据库全文搜索批量替换字符串
- linux 全文查找和替换
- linux 全文查找和替换
- 搜索和替换工具
- vi搜索和替换
- vim搜索和替换
- vim搜索和替换
- linux技巧汇总(持续更新):批量替换,全文搜索
- Linux全文查找、替换和删除
- 全文搜索
- 全文搜索
- 全文搜索
- 全文搜索
- vi的搜索和替换
- VIM中的搜索和替换
- VIM 搜索和替换方法
- VIM中的搜索和替换
- 建立个人知识引擎的重要性
- PHP新手上路(二)
- Geometry对象浅析
- PHP新手上路(一)
- 再议ASP.NETDataGrid控件中的“添加新行”功能
- 全文搜索和替换
- 妙用ASP2.0中的URL映射改变网址
- 来自PHP.NET的入门教程
- AJAX实现web页面中级联菜单的设计
- 一个用于mysql的数据库抽象层函数库
- 通过系统配置来提高ASP.NET应用程序的稳定性
- 一个高ai的分页函数和一个url函数
- 从ASP.NET1.1升级到ASP.NET2.0要考虑的Cookie问题
- 这个分页函数非常高只能的