PHP batch update web content implementation code

  • 2020-03-31 20:17:21
  • OfStack


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


//Specified folder
$path=$path."\web\study\"; 

//Get all the files
$s=explode("n",trim(`dir/b/o:gn $path`)); 

//Gets all the HTML file names under the folder
$num=count($s); 
for($i=0;$i<=$num;$i++){ 
if(strpos($s[$i],".htm")==0){ 
unset($s[$i]); 
} 
} 
//print_r($s); 



//Batch page
foreach($s as $value){ 
editfile("D:\MYOA\webroot\web\study\".$value); 
echo $value." Has been updated !<br>"; 
} 
//editfile("D:\MYOA\webroot\web\study\0105_5.htm"); 
echo "THE END"; 


//Custom function: intercepts the content between tags
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); 
} 

//Edit the file
function editfile($str){ 
//$str="D:\MYOA\webroot\web\study\".$str 
//Get HTML content
$file=@fopen($str,"r"); 
while(!feof($file)){ 
$result.=fgets($file,9999); 
} 
fclose($file); 


//Alternative content
$result=str_replace(" Lao wang's digital accessories shop: wang Po digital "," Arashi horizon  ",$result); 
$result=str_replace(" Photography lighting "," Back to tutorial home ",$result); 
$result=str_replace('width="407"','width="770"',$result); 
$result=str_replace("http://shop1289309.taobao.com","http://www.lansj.com",$result); 
$result=str_replace(" For pharaoh ID There are: pccity,joshwang,joshwanggg","",$result); 
$result=str_replace("QQ:123709080 MSN:joshwanggg@hotmail.com",' Online consulting : <a target=blank href=tencent://message/?uin=35501547&Site= Arashi horizon photography &Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:35501547:10 alt=" Click start consulting "></a> <a target=blank href=tencent://message/?uin=56025743&Site= Arashi horizon photography &Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:56025743:10 alt=" Click start consulting "></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"> Oak camera club </a>','<a href="http://bbs.lansj.com"> LAN vision photography forum </a>',$result); 
$result=str_replace('http://www.zonline.com.cn/photo/img/','http://www.lansj.com/study/',$result); 
$result=str_replace('<p> If you have any questions about digital equipment and accessories QQ : 123709080 Enquiries, digital cameras and related accessories franchise: <a href="http;//Shop1289309.taobao.com "> Wangpo digital </ 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)." -  Arashi horizon photography ",$result); 
$result=str_replace(" Photography of heaven and earth ",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)." -  Arashi horizon photography ",$result); 

//echo $result; 

//Update the HTML
$file=@fopen($str,"w"); 
fwrite($file,$result); 
fclose($file); 
} 
?>

Related articles: