xml生成sitemap.xml格式
2018/12/14    

xml生成:

<?PHP
$data_array = array(
    array(
    'title' => 'title1',
    'content' => 'content1',
        'pubdate' => '2009-10-11',
    ),
    array(
    'title' => 'title2',
    'content' => 'content2',
    'pubdate' => '2009-11-11',
    )
);
$title_size = 1;
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
$xml .= "<article>\n";
foreach ($data_array as $data) {
$xml .= create_item($data['title'], $title_size, $data['content'], $data['pubdate']);
}
$xml .= "</article>\n";
echo $xml;
//  创建XML单项
function create_item($title_data, $title_size, $content_data, $pubdate_data)
{
    $item = "<item>\n";
    $item .= "<title size=\"" . $title_size . "\">" . $title_data . "</title>\n";
    $item .= "<content>" . $content_data . "</content>\n";
    $item .= " <pubdate>" . $pubdate_data . "</pubdate>\n";
    $item .= "</item>\n";
    return $item;
}
?>

百度sitemap.xml格式

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/">
<url>
<loc>https://www.qk6080.com/p_198158.html</loc>
<mobile:mobile type="pc,mobile"/>
<lastmod>2018-12-14</lastmod>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
<url>
</urlset>

谷歌sitemap.xml格式

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.qk6080.com/p_198158.html</loc>
<mobile:mobile type="pc,mobile"/>
<lastmod>2018-12-14</lastmod>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
<url>
</urlset>

robots.txt配置

User-agent: *
Disallow: /add/
Sitemap: https://www.server.com/google.xml

robots.txt

配置sitemap只有google,bing等认识,国内的sprider一律不认