Home  >  Article  >  Backend Development  >  PHP 批量更新网页内容实现代码_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:20:07925browse
复制代码 代码如下:
$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;$iif(strpos($s[$i],".htm")==0){
unset($s[$i]);
}
}
//print_r($s);



//批处理网页
foreach($s as $value){
editfile("D:\\MYOA\\webroot\\web\\study\\".$value);
echo $value."已更新!
";
}
//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:joshwanggg@hotmail.com",'在线咨询: 点击开始咨询 点击开始咨询',$result);
$result=str_replace('http://www.zonline.com.cn
',"",$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('橡树摄影俱乐部','岚视界摄影论坛',$result);
$result=str_replace('http://www.zonline.com.cn/photo/img/','http://www.lansj.com/study/',$result);
$result=str_replace('

如果你对数码器材和配件有什么问题可以发QQ:123709080问询,数码相机及相关配件专营:王婆数码

',"",$result);

$result=str_replace("Untitled Document",substr(str_replace(chr(32),"",str_replace(chr(10),"",str_replace("","",str_replace(chr(13),"",get_body('


','

',$result))))),0,28)." - 岚视界摄影",$result);
$result=str_replace("摄影天地",substr(str_replace(chr(32),"",str_replace(chr(10),"",str_replace("

","",str_replace(chr(13),"",get_body('','',$result))))),0,28)." - 岚视界摄影",$result);

//echo $result;

//更新HTML
$file=@fopen($str,"w");
fwrite($file,$result);
fclose($file);
}
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn