当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP 批量更新网页内容实现代码

PHP
如何防止入侵:My SQL各种攻击方法大全
教你使用MySQL:MySQL常用命令一览
教你如何在linux下建立mysql镜像数据库
实际应用:MySQL5存储过程编写实践
MySQL手册版本 5.0.20-MySQL同步
MySQL手册版本 5.0.20-MySQL同步(二)
MySQL手册版本 5.0.20-MySQL同步(三)
MySQL 版本 卸载与安装
[Mysql]Mysql中mysqldump命令使用详解 (1)
[Mysql]Mysql中mysqldump命令使用详解 (2)
通过缓存数据库结果提高PHP性能(1)
通过缓存数据库结果提高PHP性能(2)
通过缓存数据库结果提高PHP性能(3)
通过缓存数据库结果提高PHP性能(4)
如何使用SQL Server 2005 INSTEAD-OF触发器
实例讲解MySQL数据库的查询优化技术 (1)(2)
实例讲解MySQL数据库的查询优化技术 (1)
高手心得:提高MySQL性能的方法 (1)(2)
高手心得:提高MySQL性能的方法 (1)
工作笔记:配置MySQL为高可用集群 (1)(2)

PHP 批量更新网页内容实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 125 ::
收藏到网摘: n/a

lost63原创的,批量替换内容的php代码
复制代码 代码如下:

<?php
$path=$DOCUMENT_ROOT;
$path=str_replace("/","\\",$path);

//指定文件夹
$path=$path."\\web\\study\\";
//得到所有文件
$s=explode("\n",trim(`dir/b/o:gn $path`));
//得到文件夹下的所有HTML文件名
$num=count($s);
for($i=0;$i<=$num;$i++){
if(strpos($s[$i],".htm")==0){
unset($s[$i]);
}
}
//print_r($s);

//批处理网页
foreach($s as $value){
editfile("D:\\MYOA\\webroot\\web\\study\\".$value);
echo $value."已更新!<br>";
}
//editfile("D:\\MYOA\\webroot\\web\\study\\0105_5.htm");
echo "THE END";

//自定义函数:截取标签之间的内容
function get_body($start_str,$end_str,$content){
$start_str_num=strlen($start_str);
$end_str_num=strlen($end_str);
$a=strpos($content,$start_str)+$start_str_num;
$b=strpos($content,$end_str)-strpos($content,$start_str)-$start_str_num;
return substr($content,$a,$b);
}
//编辑文件
function editfile($str){
//$str="D:\\MYOA\\webroot\\web\\study\\".$str
//取得HTML内容
$file=@fopen($str,"r");
while(!feof($file)){
$result.=fgets($file,9999);
}
fclose($file);

//替换内容
$result=str_replace("老王的数码配件店:王婆数码","岚视界 ",$result);
$result=str_replace("摄影网校","回到教程首页",$result);
$result=str_replace('width="407"','width="770"',$result);
$result=str_replace("http://shop1289309.taobao.com","http://www.lansj.com",$result);
$result=str_replace("老王用的ID有:pccity,joshwang,joshwanggg","",$result);
$result=str_replace("QQ:123709080 MSN:[email protected]",'在线咨询: <a target=blank href=tencent://message/?uin=35501547&Site=岚视界摄影&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:35501547:10 alt="点击开始咨询"></a> <a target=blank href=tencent://message/?uin=56025743&Site=岚视界摄影&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:56025743:10 alt="点击开始咨询"></a>',$result);
$result=str_replace('<a href="http://www.zonline.com.cn">http://www.zonline.com.cn</a><br>',"",$result);
$result=str_replace('http://www.zonline.com.cn/photo/school/scgs/',"http://www.lansj.com/study/",$result);
$result=str_replace('http://www.yimei.net/css/',"http://www.lansj.com/study/",$result);
$result=str_replace('http://www.zonline.com.cn/photo/school/img/',"http://www.lansj.com/study/",$result);
$result=str_replace('http://www.yimei.net/inc/',"http://www.lansj.com/study/",$result);
$result=str_replace('<a href="http://www.xiangshu.com">橡树摄影俱乐部</a>','<a href="http://bbs.lansj.com">岚视界摄影论坛</a>',$result);
$result=str_replace('http://www.zonline.com.cn/photo/img/','http://www.lansj.com/study/',$result);
$result=str_replace('<p>如果你对数码器材和配件有什么问题可以发QQ:123709080问询,数码相机及相关配件专营:<a href="http;//shop1289309.taobao.com">王婆数码</a></p>',"",$result);
$result=str_replace("Untitled Document",substr(str_replace(chr(32),"",str_replace(chr(10),"",str_replace("</p>","",str_replace(chr(13),"",get_body('<p align="center" class="h1"><br>','<p align="left">',$result))))),0,28)." - 岚视界摄影",$result);
$result=str_replace("摄影天地",substr(str_replace(chr(32),"",str_replace(chr(10),"",str_replace("</p>","",str_replace(chr(13),"",get_body('<span class="text">','</span>',$result))))),0,28)." - 岚视界摄影",$result);
//echo $result;
//更新HTML
$file=@fopen($str,"w");
fwrite($file,$result);
fclose($file);
}
?>