百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

seo

> 编程语言
开源

一个简单的 PHP 库,可帮助开发人员更好地进行页面 SEO 优化

359 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个简单的 PHP 库,可帮助开发人员更好地进行页面 SEO 优化

PHP SEO

The SEO library for PHP is a simple and powerful PHP library to help developers do better on-page SEO optimizations.

PHP SEO features:

  • [] Generate Rich Results schema.org ld+json
  • [] Generate Meta Tags with X (Twitter) and Open Graph Support
  • [] Generate XML Sitemaps (supports: News Sitemaps, Images Sitemaps, Video Sitemaps, Index Sitemaps)
  • [] IndexNow and Google Indexing API
  • [✅] Schema Rich Results Validator
  • [] Zero Dependencies

Installation:

bash
composer require melbahja/seo

Documentation

You can read the docs Here.

Usage:

Check this simple examples.

Generate schema.org

php
use Melbahja\Seo\Schema;
use Melbahja\Seo\Schema\Thing;
use Melbahja\Seo\Schema\Organization;

$schema = new Schema(
    new Organization([
        'url'          => 'https://example.com',
        'logo'         => 'https://example.com/logo.png',
        'contactPoint' => new Thing(type: 'ContactPoint', props: [
            'telephone' => '+1-000-555-1212',
            'contactType' => 'customer service'
        ])
    ])
);

echo $schema;

Results: (formatted)

xml
…

Results:

…

Meta Tags

…

Results:

xml
PHP SEO

Sitemaps

Generate XML sitemaps with support for images, videos, news, and localized URLs.

Basic Usage

php
use Melbahja\Seo\Sitemap;

$sitemap = new Sitemap(
    baseUrl: 'https://example.com',
    saveDir: '/path/to_save/files',
);

$sitemap->links('blog.xml', function($map)
{
    $map->loc('/blog')
            ->changeFreq('daily')
            ->priority(0.8)
            ->loc('/blog/my-new-article')
            ->changeFreq('weekly')
            ->lastMod('2024-01-15')
            ->loc('/اهلا-بالعالم')
            ->changeFreq('weekly');

    $map->loc('/blog/hello')->changeFreq('monthly');
});

$sitemap->render();

Options

Option Description Required Default
saveDir Generated sitemaps storage path Yes -
sitemapBaseUrl Custom URL for generated sitemaps No Base URL
indexName Custom sitemap index name No sitemap.xml
mode Output mode (FILE, MEMORY, STREAM, TEMP) No TEMP

URL Methods

php
$builder->loc('/page')               // URL path relative or absolute
        ->priority(0.8)              // Priority 0.0-1.0
        ->changeFreq('weekly')       // always, hourly, daily, weekly, monthly, yearly, never
        ->lastMod('2024-01-15')      // Last modified date in string or unix ts
        ->image('/image.jpg')        // Add image (requires 'images' => true)
        ->video('Title', [...])      // Add video (requires 'videos' => true)
        ->alternate('/es/page', 'es'); // Add hreflang alternate

Advanced Features

Image Sitemaps

php
$sitemap->links(['name' => 'gallery.xml', 'images' => true], function($builder)
{
    $builder->loc('/gallery/1')
            ->image('/images/photo1.jpg', [
                'title' => 'Photo Title',
                'caption' => 'Photo caption'
            ]);
});

Video Sitemaps

php
$sitemap->links(['name' => 'videos.xml', 'videos' => true], function($builder)
{
    $builder->loc('/video/page')
            ->video('Video Title', [
                'thumbnail' => '/thumb.jpg',
                'description' => 'Video description',
                'content_loc' => '/video.mp4'
            ]);
});

News Sitemaps

php
use Melbahja\Seo\Sitemap\NewsBuilder;

$sitemap->news('news.xml', function(NewsBuilder $builder)
{
    $builder->setPublication('Your News', 'en');

    $builder->loc('/article/1')
            ->news([
                'title' => 'Article Title',
                'publication_date' => '2024-01-15T10:00:00Z',
                'keywords' => 'news, breaking'
            ]);
});

Multilingual Sitemaps

php
$sitemap->links(['name' => 'multilang.xml', 'localized' => true], function($builder)
{
    $builder->loc('/page')
            ->alternate('/es/page', 'es')
            ->alternate('/fr/page', 'fr');
});

Output Modes

TEMP Mode (Default)

php
$sitemap = new Sitemap('https://example.com',
[
    'saveDir' => './storage',
    'mode' => OutputMode::TEMP
]);
$sitemap->render(); // Saves to temp dir and save to disk only on generation success.

File Mode

php
$sitemap = new Sitemap('https://example.com',
[
    'saveDir' => './storage',
    'mode' => OutputMode::FILE
]);
$sitemap->render(); // Saves to disk

Memory Mode

php
$sitemap = new Sitemap('https://example.com', [
    'mode' => OutputMode::MEMORY
]);
$xml = $sitemap->render(); // Returns XML string

Stream Mode

php
$stream = fopen('sitemap.xml', 'w');
$builder = new LinksBuilder(
    baseUrl: 'https://example.com',
    stream: $stream, // defaults to stdout
    mode: OutputMode::STREAM,
);
$builder->loc('/page')->render();
fclose($stream);

Complete Example

…

Indexing API

Submit URLs to search engines for instant indexing using Google Indexing API and IndexNow protocol.

Google Indexing API

php
use Melbahja\Seo\Indexing\GoogleIndexer;
use Melbahja\Seo\Indexing\URLIndexingType;

$indexer = new GoogleIndexer('your-google-access-token');

// Index single URL
$indexer->submitUrl('https://www.example.com/page');

// Index multiple URLs
$indexer->submitUrls([
    'https://www.example.com/page1',
    'https://www.example.com/page2'
]);

// Delete URL from index
$indexer->submitUrl('https://www.example.com/deleted-page', URLIndexingType::DELETE);

IndexNow Protocol

php
use Melbahja\Seo\Indexing\IndexNowIndexer;

$indexer = new IndexNowIndexer('your-indexnow-api-key');

// Submit to all supported engines
$indexer->submitUrl('https://www.example.com/page');

// Submit multiple URLs
$indexer->submitUrls([
    'https://www.example.com/page1',
    'https://www.example.com/page2'
]);

AI LLMs.txt Support

If you find LLMs.txt valuable for your use case, contributions are welcome! Feel free to submit a PR.

Who's Using melbahja/seo?

  • Tiki Wiki CMS Groupware - All-in-one collaboration platform
  • Castopod - Open-source podcast hosting platform
  • [ADD YOURS]

and many more non-open source projects.

Sponsors

Special thanks to friends who support this work financially:

References

  • Sitemaps protocol (https://www.sitemaps.org/protocol.html)
  • Build Sitemaps (https://support.google.com/webmasters/answer/183668?hl=en)
  • News Sitemaps (https://support.google.com/webmasters/answer/74288)
  • Image Sitemaps (https://support.google.com/webmasters/answer/178636)
  • Video Sitemaps (https://support.google.com/webmasters/answer/80471)
  • Mobile (https://developers.google.com/search/mobile-sites/mobile-seo/other-devices)

License

MIT Copyright (c) Mohamed Elbahja

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPgoogle-indexing-apiindexing-apiindexnowjson-ld

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言