當前位置:首頁 » 編程語言 » phpsitemap

phpsitemap

發布時間: 2023-01-23 10:24:17

php獲取sitemap裡面的網址URL並且保存到本地的TXT文本裡面

讀取sitemap.xml我就不寫了,

關鍵代碼:

preg_match_all('/<loc>(.*?)</loc>/',$content,$out,PREG_PATTERN_ORDER);
var_mp($out);

⑵ 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怎樣做sitemap

簡單的講,站點地圖就像目錄一樣。
像你這樣的情況,你可以直接做個頁面,之後把站點地圖的鏈接加上。

⑷ 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呢?

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

⑸ 如何讓網站的sitemap進行自動更新,網站是使用php寫的

Sitemap 可方便網站管理員通知搜索引擎他們網站上有哪些可供抓取的網頁。最簡單的 Sitemap 形式,就是XML 文件,在其中列出網站中的網址以及關於每個網址的其他元數據(上次更新的時間、更改的頻率以及相對於網站上其他網址的重要程度為何等),以便搜索引擎可以更加智能地抓取網站。
當php提交的時候,對應事件代碼如下:

$xml="sitemap.xml";
$sitemap='<?xmlversion="1.0"encoding="UTF-8"?>

這里是網址比如(3tii.com)
'.date("Y-m-d",time()).'
always
1.0

';
$fpxml=fopen($xml,"w+");
fwrite($fpxml,$sitemap);
fclose($fpxml);sitemap.xml是你對應的文件,如果路徑不同,前面可能需要加"../"之類的,priority
改為0.8好些。

⑹ php如何查找網站所有頁面出來做sitemap

這個有第三方工具,Google sitemap生成工具。不過不是很完全,最好的是自己寫程序來完成這個功能。

⑺ sitemap正確寫法,php zblog版本,其他都一樣

header("Content-type: text/xml");header('HTTP/1.1 200 OK');require'zb_system/function/c_system_base.php';global$zbp;$zbp->host ='http://'. $_SERVER['SERVER_NAME'] .'/';$str ='<?xml version="1.0" encoding="UTF-8"?>';$str .='<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">';if(!isset($_GET['index'])) {    $str .='<url>';    $str .='<loc>'. $zbp->host .'</loc>';    $str .='<mobile:mobile type="pc,mobile"/>';    $str .='<lastmod>'. date('Y-m-d', time()) .'</lastmod>';    $str .='<changefreq>daily</changefreq>';    $str .='<priority>1.0</priority>';    $str .='</url>';    $allCats = $zbp->GetCategoryList();foreach($allCatsas$cat) {        $str .='<url>';        $str .='<loc>'. $cat->Url .'</loc>';//        $str .= '<mobile:mobile type="pc,mobile"/>';$str .='<lastmod>'. date('Y-m-d', time()) .'</lastmod>';        $str .='<changefreq>daily</changefreq>';        $str .='<priority>0.8</priority>';        $str .='</url>';    }    $allTags = $zbp->GetTagList();foreach($allTagsas$tag) {        $str .='<url>';        $str .='<loc>'. $tag->Url .'</loc>';//        $str .= '<mobile:mobile type="pc,mobile"/>';//        $str .= '<lastmod>' . date('Y-m-d', time()) . '</lastmod>';$str .='<changefreq>weekly</changefreq>';        $str .='<priority>0.6</priority>';        $str .='</url>';    }    $allAuthors = $zbp->GetMemberList('*',array(array('>','mem_ID',1),array('>','mem_Articles',0)),array('mem_Level'=>'ASC'),2000,null);foreach($allAuthorsas$member) {        $str .='<url>';        $str .='<loc>'. $member->Url .'</loc>';//        $str .= '<mobile:mobile type="pc,mobile"/>';//        $str .= '<lastmod>' . date('Y-m-d', time()) . '</lastmod>';$str .='<changefreq>weekly</changefreq>';        $str .='<priority>0.6</priority>';        $str .='</url>';    }}else{//文章$index = $_GET['index'];    $db = $zbp->db->sql->get();    $sql = $db->select($zbp->table['Post'])->where(array('=','log_Status','0'))->orderBy(array('log_PostTime'=>'DESC'))->limit(array(1000* $index,1000))->sql;    $array = $zbp->GetListType('Post', $sql);foreach($arrayas$post) {        $str .='<url>';        $str .='<loc>'. $post->Url .'</loc>';//        $str .= '<mobile:mobile type="pc,mobile"/>';$str .='<lastmod>'. $post->Time('Y-m-d') .'</lastmod>';        $str .='<changefreq>monthly</changefreq>';        $str .='<priority>0.4</priority>';        $str .='</url>';    }}$str .='</urlset>';echo$str;unset($str);?>

sitemap,zlbog php 版本寫法, 美食匯 網站地圖 ,zblog版本,其他框架,請自行獲取文章函數

nginx 重定向配置

rewrite ^/sitemap\.xml$/sitemap.phplast;

⑻ 怎樣設置一個頁面為sitemap.php,顯示最新100條帖子

php的好處是動態生成,可以根據你的發布自動生成,而不用你每次更新欄目要調整欄目的時間等。。。 但php的壞處也有,就是很多引擎不支持,那我建議你,放一個php,在放一個xml,這樣是最好的。 還有看一下你php的代碼,加上一條自動生成xml,就...

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

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

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

⑽ thinkphp定時自動生成sitemap怎麼代碼

第一步當然是創建sitemap的方法了,因為sitemap裡面是要把博客裡面所有文章的url都放上去,我的文章url格式是 域名/文章id 的格式,所以要先從資料庫裡面把文章id讀取出來。因為寫這個sitemap只需要id和時間,所以就讀取了這兩個欄位,並且對id進行倒序排序。
thinkphp寫個人博客之生成sitemap
讀取出來以後當然是將讀取出來的數據重新組合,組合成sitemap需要的格式。
xml要以xml version="1.0" encoding="utf-8"開頭
每個url寫在loc標簽裡面
用foreach把數據進行組合,最後閉合urlset標簽
我這裡面的C('domain')是從配置文件裡面讀取我自己博客的域名
整個sitemap的格式就這樣搞定了,接下來就是寫入到文件裡面去,這樣就大功告成了。
當然最後寫入到文件裡面的時候也可以使用file_put_contents()這個函數,這個函數的話更為簡單,一步到位,不用fopen和fclose什麼的了
當然,生成sitemap成功以後最好有個提示不是,這樣也好一點,對吧
就簡單一點,判斷下fclose(),為真則提示成功
作為一個優秀的程序猿,我們就得多寫多練多分享。
注意事項
sitemap的格式注意不要弄錯,詳細內容可參照網路站長平台的文檔

熱點內容
匈牙利演算法最大 發布:2025-07-20 10:52:54 瀏覽:852
sql日期列表 發布:2025-07-20 10:52:09 瀏覽:36
linux谷歌瀏覽器安裝 發布:2025-07-20 10:44:07 瀏覽:335
好用的反編譯 發布:2025-07-20 10:32:44 瀏覽:57
9月9日復刻先祖是什麼安卓 發布:2025-07-20 10:30:27 瀏覽:606
流控資料庫 發布:2025-07-20 10:27:16 瀏覽:414
雲搶包網站源碼 發布:2025-07-20 10:25:38 瀏覽:121
安卓多開為什麼一直打不開 發布:2025-07-20 10:25:00 瀏覽:883
ios移動文件夾 發布:2025-07-20 10:24:50 瀏覽:690
數控機床編程步驟 發布:2025-07-20 10:14:22 瀏覽:97