Heim >php教程 >php手册 >生成网站地图,并通知搜索引擎的更新

生成网站地图,并通知搜索引擎的更新

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 19:32:191185Durchsuche

这个类可以用来生成网站地图,并通知搜索引擎的更新。 建立一个网站地图文件的URL列表。URL的最后修改日期,变更频率和优先级。该sitemap文件可能被保存在压缩格式。 并且将更新网站地图地址的网站的robots.txt文件。 当更新网站地图,也可以通知类的搜索引擎

这个类可以用来生成网站地图,并通知搜索引擎的更新。

建立一个网站地图文件的URL列表。URL的最后修改日期,变更频率和优先级。该sitemap文件可能被保存在压缩格式。

并且将更新网站地图地址的网站的robots.txt文件。

当更新网站地图,也可以通知类的搜索引擎,如谷歌,必应,雅虎和Ask。

地图类太长下载地址:http://www.codepearl.com/files/167.html PHP

源码与演示:源码出处 演示出处

生成网站地图,并通知搜索引擎的更新 生成网站地图,并通知搜索引擎的更新
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <?php
        // include class
        include 'SitemapGenerator.php';

        // create object
        $sitemap = new SitemapGenerator("http://www.codepearl.com/");

        // add urls
        $sitemap->addUrl("http://www.codepearl.com",                date('c'),  'daily',    '1');
        $sitemap->addUrl("http://www.codepearl.com/page1",          date('c'),  'daily',    '0.5');
        $sitemap->addUrl("http://www.codepearl.com/page2",          date('c'),  'daily');
        $sitemap->addUrl("http://www.codepearl.com/page3",          date('c'));
        $sitemap->addUrl("http://www.codepearl.com/page4");
        $sitemap->addUrl("http://www.codepearl.com/page/subpage1",  date('c'),  'daily',    '0.4');
        $sitemap->addUrl("http://www.codepearl.com/page/subpage2",  date('c'),  'daily');
        $sitemap->addUrl("http://www.codepearl.com/page/subpage3",  date('c'));
        $sitemap->addUrl("http://www.codepearl.com/page/subpage4");

        // create sitemap
        $sitemap->createSitemap();

        // write sitemap as file
        $sitemap->writeSitemap();

        // update robots.txt file
        $sitemap->updateRobots();

        // submit sitemaps to search engines
        $sitemap->submitSitemap();
        ?>
    </body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <?php
        $time = explode(" ",microtime());
        $time = $time[1];

        // include class
        include 'SitemapGenerator.php';
        // create object
        $sitemap = new SitemapGenerator("http://www.codepearl.com/", "../");

        // will create also compressed (gzipped) sitemap
        $sitemap->createGZipFile = true;

        // determine how many urls should be put into one file
        $sitemap->maxURLsPerSitemap = 10000;

        // sitemap file name
        $sitemap->sitemapFileName = "sitemap.xml";

        // sitemap index file name
        $sitemap->sitemapIndexFileName = "sitemap-index.xml";

        // robots file name
        $sitemap->robotsFileName = "robots.txt";

        $urls = array(
            array("http://www.codepearl.com",                    date('c'),  'daily',    '1'),
            array("http://www.codepearl.com/mainpage1",          date('c'),  'daily',    '0.5'),
            array("http://www.codepearl.com/mainpage2",          date('c'),  'daily'),
            array("http://www.codepearl.com/mainpage3",          date('c')),
            array("http://www.codepearl.com/maonpage4"));

        // add many URLs at one time
        $sitemap->addUrls($urls);

        // add urls one by one
        $sitemap->addUrl("http://www.codepearl.com/page1",          date('c'),  'daily',    '0.5');
        $sitemap->addUrl("http://www.codepearl.com/page2",          date('c'),  'daily');
        $sitemap->addUrl("http://www.codepearl.com/page3",          date('c'));
        $sitemap->addUrl("http://www.codepearl.com/page4");
        $sitemap->addUrl("http://www.codepearl.com/page/subpage1",  date('c'),  'daily',    '0.4');
        $sitemap->addUrl("http://www.codepearl.com/page/subpage2",  date('c'),  'daily');
        $sitemap->addUrl("http://www.codepearl.com/page/subpage3",  date('c'));
        $sitemap->addUrl("http://www.codepearl.com/page/subpage4");

        try {
            // create sitemap
            $sitemap->createSitemap();

            // write sitemap as file
            $sitemap->writeSitemap();

            // update robots.txt file
            $sitemap->updateRobots();

            // submit sitemaps to search engines
            $result = $sitemap->submitSitemap("yahooAppId");
            // shows each search engine submitting status
            echo "<pre class="brush:php;toolbar:false">";
            print_r($result);
            echo "
"; } catch (Exception $exc) { echo $exc->getTraceAsString(); } echo "Memory peak usage: ".number_format(memory_get_peak_usage()/(1024*1024),2)."MB"; $time2 = explode(" ",microtime()); $time2 = $time2[1]; echo "
Execution time: ".number_format($time2-$time)."s"; ?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP打开sqlite的两种方式Nächster Artikel:FirePHP使用详解