PHP 批量更新網(wǎng)頁(yè)內(nèi)容實(shí)現(xiàn)代碼
<?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);
//批處理網(wǎng)頁(yè)
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";
//自定義函數(shù):截取標(biāo)簽之間的內(nèi)容
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內(nèi)容
$file=@fopen($str,"r");
while(!feof($file)){
$result.=fgets($file,9999);
}
fclose($file);
//替換內(nèi)容
$result=str_replace("老王的數(shù)碼配件店:王婆數(shù)碼","嵐視界 ",$result);
$result=str_replace("攝影網(wǎng)校","回到教程首頁(yè)",$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",'在線咨詢(xún): <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="點(diǎn)擊開(kāi)始咨詢(xún)"></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="點(diǎn)擊開(kāi)始咨詢(xún)"></a>',$result);
$result=str_replace('<a ,$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 <a ,$result);
$result=str_replace('http://www.zonline.com.cn/photo/img/','http://www.lansj.com/study/',$result);
$result=str_replace('<p>如果你對(duì)數(shù)碼器材和配件有什么問(wèn)題可以發(fā)QQ:123709080問(wèn)詢(xún),數(shù)碼相機(jī)及相關(guān)配件專(zhuān)營(yíng):<a href="http;//shop1289309.taobao.com">王婆數(shù)碼</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);
}
?>
相關(guān)文章
PHP反射類(lèi)ReflectionClass和ReflectionObject的使用方法
PHP反射類(lèi)ReflectionClass和ReflectionObject2013-11-11php中獲取關(guān)鍵詞及所屬來(lái)源搜索引擎名稱(chēng)的代碼
有時(shí)候我們需要知道用戶(hù)通過(guò)哪個(gè)搜索引擎,通過(guò)拿個(gè)關(guān)鍵詞訪問(wèn)我們頁(yè)面,當(dāng)然js也可以實(shí)現(xiàn),但這里介紹下php的實(shí)現(xiàn)代碼。2011-02-02php中將數(shù)組轉(zhuǎn)成字符串并保存到數(shù)據(jù)庫(kù)中的函數(shù)代碼
為了方便可以把php的數(shù)組轉(zhuǎn)換為 字符串保存到數(shù)據(jù)庫(kù)中。當(dāng)需要用時(shí)就可以取出字符串再轉(zhuǎn)成數(shù)組即可。下為為php數(shù)組與字符串相互轉(zhuǎn)換的自定義函數(shù)2013-09-09在WAMP環(huán)境下搭建ZendDebugger php調(diào)試工具的方法
一直以來(lái),寫(xiě)php都是用Dreamweaver,有時(shí)候真是痛苦啊,出現(xiàn)一個(gè)bug,想看一些元素的值,必須用echo輸出來(lái)才知道,現(xiàn)在了解到一個(gè)斷點(diǎn)調(diào)試?yán)?,php終于也能像java、.NET那樣斷點(diǎn)調(diào)試,這就是——ZendDebugger2011-07-07php通過(guò)pecl方式安裝擴(kuò)展的實(shí)例講解
下面小編就為大家分享一篇php通過(guò)pecl方式安裝擴(kuò)展的實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02php和html的區(qū)別點(diǎn)詳細(xì)總結(jié)
在本篇文章里小編給大家整理了關(guān)于php和html的區(qū)別點(diǎn),有需要的朋友們可以參考下。2019-09-09PHP實(shí)現(xiàn)基于面向?qū)ο蟮膍ysqli擴(kuò)展庫(kù)增刪改查操作工具類(lèi)
這篇文章主要介紹了PHP實(shí)現(xiàn)基于面向?qū)ο蟮膍ysqli擴(kuò)展庫(kù)增刪改查操作工具類(lèi),結(jié)合實(shí)例形式分析了mysqli增刪改查操作類(lèi)的封裝與使用技巧,需要的朋友可以參考下2017-07-07PHP利用正則表達(dá)式將相對(duì)路徑轉(zhuǎn)成絕對(duì)路徑的方法示例
這篇文章主要介紹了PHP利用正則表達(dá)式將相對(duì)路徑轉(zhuǎn)成絕對(duì)路徑的方法,文中給出了詳細(xì)的示例代碼,大家可以整合成一個(gè)方法,在需要的地方調(diào)用,非常的不錯(cuò)。需要的朋友們下面來(lái)一起看看吧。2017-02-02