stolt/llms-txt-php

A library for llms.txt Markdown files.

v1.0.0 2025-06-24 12:42 UTC

This package is auto-updated.

Last update: 2025-06-25 16:17:13 UTC


README

This library supports you in creating and reading llms.txt Markdown files via PHP. A good example llms.txt file is the one from the uv project.

What's llms.txt?

Think of it like robots.txt for LLMs. The evolving spec is available over here.

Installation and usage

composer require stolt/llms-txt-php

Creating a llms.txt file

use Stolt\LlmsTxt\LlmsTxt;
use Stolt\LlmsTxt\Section;
use Stolt\LlmsTxt\Section\Link;

$section1 = (new Section())->name('Section name')
    ->addLink((new Link())->urlTitle('Link title')
        ->url('https://link_url')->urlDetails('Optional link details')
    );
$section2 = (new Section())->name('Optional')
    ->addLink((new Link())->urlTitle('Link title')
        ->url('https://link_url')
    );

$llmsTxt = (new LlmsTxt())->title('Test title')
  ->description('Test description')
  ->details('Test details')
  ->addSection($section1)
  ->addSection($section2)
  ->toString();

Reading a llms.txt file and it's parts

use Stolt\LlmsTxt\LlmsTxt;

$llmsText = (new LlmsTxt())->parse('/path/to/llmsTxt.md');
$title = $llmsText->getTitle();
$description = $llmsText->getDescription();
$details = $llmsText->getDetails();
$sections = $llmsText->getSections();

Running tests

composer test

License

This library is licensed under the MIT license. Please see LICENSE.md for more details.

Changelog

Please see CHANGELOG.md for more details.

Contributing

Please see CONTRIBUTING.md for more details.