導航:首頁 > 編程語言 > php生成網站地圖

php生成網站地圖

發布時間:2023-11-16 14:19:25

『壹』 php怎麼生成sitemap.xml

/**
*生成站點地圖
*/
classsitemap{
private$sitemapFile=array();
private$oldxml=null;
private$newxml=null;
public$error=null;
publicfunction__construct($sitemapFile){
$this->sitemapFile=$sitemapFile;
if(is_file($this->sitemapFile)){
$data=file_get_contents($this->sitemapFile);
if($data){
$this->oldxml=newSimpleXMLElement($data);
}else{
$this->error='讀取站點地圖文件失敗';
}
}else{
$this->oldxml=$this->createEmptySitemap();
}
$this->newxml=$this->createEmptySitemap();
}
(){
$str='<?xmlversion="1.0"encoding="UTF-8"?>';
$str.='<urlsetxmlns="http://www.sitemaps.org/schemas/sitemap/0.9"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"></urlset>';
returnnewSimpleXMLElement($str);
}
publicfunctionaddChilds($urlArr){
$urlArr=(array)$urlArr;
foreach($urlArras$url){
$priority=0.5;
$lastmod=date('Y-m-d');
$changefreq='weekly';
if(stripos($url,'.html')){
$priority=1;
$changefreq='monthly';
}
if($oldXmlUrl=$this->findOldXmlUrl($url)){
$priority=$oldXmlUrl->priority;
$lastmod=$oldXmlUrl->lastmod;
$changefreq=$oldXmlUrl->changefreq;
}
$rating=$this->newxml->addChild('url');
$rating->addChild('loc',$url);
$rating->addChild('priority',$priority);
$rating->addChild('lastmod',$lastmod);
$rating->addChild('changefreq',$changefreq);
}
}
publicfunctionfindOldXmlUrl($url){
$oldXmlUrl='';
foreach($this->oldxml->urlas$key=>$xmlUrl){
if($xmlUrl->loc==$url){
$oldXmlUrl=$xmlUrl;
unset($this->oldxml->url[$key]);
break;
}
}
return$oldXmlUrl;
}
publicfunctionsave(){
$data=$this->newxml->asXML();
if(file_put_contents($this->sitemapFile,$data)===false){
$this->error='寫入站點地圖數據失敗';
returnfalse;
}
returntrue;
}
}

上面這個是我個人博客生成站點地圖用的類。

客戶端調用代碼如下:

$sitemapFile='Sitemap.xml';
$sitemap=newsitemap($sitemapFile);

if($sitemap->error){
die($sitemap->error);
}

$newUrl=[
'http://www.kiscms.com/content/28.html'
];

$sitemap->addChilds();

if(!$sitemap->save()){
die($sitemap->error);
}

關鍵的問題是,你如何得到整站的url呢?

我個人博客的解決方法是寫了個蜘蛛程序爬出來的。

『貳』 php生成百度移動Sitemap協議XML格式文件,其中有兩個標簽不知怎樣加進去<mobile:mobile type="mobile"/>

打開愛站SEO工具包,找到網站地圖/sitemap,點擊進入登錄或注冊頁面,如果所示1

登錄之後,點擊添加網站,輸入網站域名www.meng10000.com,點擊保存,如圖所示2

點擊默認分類下面的網站域名,設置基本信息和抓取更新頻率後,點擊抓爬,如圖所示3和4

接下來等待抓爬完成或者自己手動點擊停止,查看,生成XML文件,如圖所示5和6

然後,打開文件目錄,找到對應sitemap.xml文件和robots.txt文件,將其全部上傳到網站伺服器根目錄下。

6
最後,打開網路站長平台,鏈接提交,提交sitemap地址,之後就等待網路蜘蛛抓取收錄你的網站吧,如圖所示。

『叄』 怎麼用php實現自動生成站點地圖的XML文件

需要做的就是新建一個地圖模板,模板-增加自定義頁面模板。

在瀏覽器裡面輸入:域名/sitemap.html,就能夠看到網站地圖了。

閱讀全文

與php生成網站地圖相關的資料

熱點內容
linuxwss 瀏覽:848
一個軟體需要登錄伺服器地址 瀏覽:923
哪裡有解壓程序 瀏覽:299
java靜態方法內存 瀏覽:545
我的世界ec伺服器如何帶vip 瀏覽:737
什麼是由解析器域名和伺服器構成 瀏覽:414
自動識別電影信息源碼 瀏覽:849
柱筋箍筋加密區怎麼算 瀏覽:48
鋼筋中加密15倍是什麼意思 瀏覽:366
esc加密演算法 瀏覽:518
linux運行exe命令 瀏覽:124
一級建造師管理pdf 瀏覽:720
如何更改伺服器登錄賬號 瀏覽:317
看pdf文件軟體 瀏覽:183
android恢復模式 瀏覽:808
生命令人憂 瀏覽:597
魔獸搬磚怎麼選擇伺服器 瀏覽:771
程序員求伯君圖片 瀏覽:827
安卓手機如何打開mark2文件 瀏覽:662
紅米手機解壓中文解壓密碼 瀏覽:316