ゼロと無限の間に

フリーでオープンソースなJavaScriptとかPHPとか。

ユーザ用ツール

サイト用ツール


php-tool-box:sitemapper

URLの配列を渡すとXML Sitemapを生成するPHP製ツール - Sitemapper

URLの配列を渡すとXML Sitemapを生成するツールを作った。
単独で使うこともできるし、サイト内のURLを全て集めるPHP製クローラー - URL Collectorと組み合わせて使えばサイト内(同一ドメイン内)でリンクされているWebページを全て調べてXML Sitemapを作ることが出来る。

Mobile Sitemapにも対応している。

ライセンス

使用例

<?php
require('htmlsql/snoopy.class.php');
require('htmlsql/htmlsql.class.php');
 
header('Content-Type: application/xml');
$arr = array();
$arr[] = 'http://www.example.com/foo?bar=123&buz=456';
$arr[] = 'http://www.example.com/foooo';
echo SiteMapper::map($arr);

ソースコード

<?php
/**
 *  Sitemapper
 *  @see       http://0-oo.net/sbox/php-tool-box/sitemapper
 *  @version   0.1.0
 *  @copyright 2010 dgbadmin@gmail.com
 *  @license   http://0-oo.net/pryn/MIT_license.txt (The MIT license)
 */
class SiteMapper {
    public static function map(array $urls, $type = 'normal') {
        $x = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
 
        if ($type == 'mobile') {
            $x .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"';
            $x .= ' xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">';
        } else {
            $x .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
        }
        $x .= "\n";
 
        $x .= "<url>\n";
        foreach ($urls as $url) {
            $x .= '<loc>' . htmlspecialchars($url) . "</loc>\n";
            if ($type == 'mobile') {
                $x .= "<mobile:mobile/>\n";
            }
        }
        $x .= "</url>\n";
 
        $x .= "</urlset>\n";
 
        return $x;
    }
}
php-tool-box/sitemapper.txt · 最終更新: 2010/02/07 23:03 by dgbadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki