PHP batch update web page content implementation code_PHP tutorial

WBOY
Release: 2016-07-21 15:41:56
Original
1152 people have browsed it

Copy code The code is as follows:

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


//Specify the folder
$path=$path."\web\study\";

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

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



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


//Custom function: intercept 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 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);


//Replacement content
$result=str_replace("Lao Wang's Digital Accessories Store: Wangpo Digital","Lan Vision",$result);
$result=str_replace("Photography Online School","Return to Tutorial Homepage",$result) ;
$result=str_replace('width="407"','width="770"',$result);
$result=str_replace("http://shop1289309.taobao.com"," http://www.lansj.com",$result);
$result=str_replace("The IDs used by Lao Wang are: pccity,joshwang,joshwanggg","",$result);
$result =str_replace("QQ:123709080 MSN:joshwanggg@hotmail.com",'Online consultation: Click to start consultation Click to start consultation ',$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('Oak Photography Club','Lan Vision Photography Forum',$result);
$result=str_replace('http://www.zonline.com.cn/photo/img/',' http://www.lansj.com/study/',$result);
$result=str_replace('

If you have any questions about digital equipment and accessories, you can send an inquiry to QQ: 123709080, Digital Specializing in cameras and related accessories: Wangpo Digital

',"",$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)." - Lan Vision Photography",$result);
$result=str_replace("Photography World",substr(str_replace(chr(32),"",str_replace(chr(10), "",str_replace("

","",str_replace(chr(13),"",get_body('','',$ result))))),0,28)." - Lan Vision Photography",$result);

//echo $result;

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321027.htmlTechArticleCopy the code as follows: ?php $path=$DOCUMENT_ROOT; $path=str_replace("/","\ ",$path); //Specify the folder $path=$path."\web\study\"; //Get all files $s=explode("n",trim(`...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template