PHPackages                             stolt/llms-txt-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. stolt/llms-txt-php

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

stolt/llms-txt-php
==================

A library for writing, reading, and validating llms.txt Markdown files.

v3.4.0(7mo ago)2210.3k↓11.3%3[1 issues](https://github.com/raphaelstolt/llms-txt-php/issues)1MITPHPPHP &gt;=8.1CI passing

Since Jun 24Pushed 3mo agoCompare

[ Source](https://github.com/raphaelstolt/llms-txt-php)[ Packagist](https://packagist.org/packages/stolt/llms-txt-php)[ RSS](/packages/stolt-llms-txt-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (25)Used By (1)

llms.txt PHP
============

[](#llmstxt-php)

[![Test Status](https://github.com/raphaelstolt/llms-txt-php/workflows/test/badge.svg)](https://github.com/raphaelstolt/llms-txt-php/workflows/test/badge.svg)[![Version](https://camo.githubusercontent.com/8e99407844b63c3c46b37ee68b86d37fbfb92d9c4347d9b5608dcb381d13db10/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746f6c742f6c6c6d732d7478742d7068702e7376673f7374796c653d666c6174)](https://packagist.org/packages/stolt/llms-txt-php)[![Downloads](https://camo.githubusercontent.com/9b3c2c161ead557d7b15eaaf8ad974a1e1661bb94cf0c85b931ac2f00226ad37/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746f6c742f6c6c6d732d7478742d706870)](https://camo.githubusercontent.com/9b3c2c161ead557d7b15eaaf8ad974a1e1661bb94cf0c85b931ac2f00226ad37/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746f6c742f6c6c6d732d7478742d706870)[![PHP Version](https://camo.githubusercontent.com/770d43133153ead0a9b8526e3352ca9933aa60cadcac54fd28aca42c3f71a613/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312b2d6666363962342e737667)](https://camo.githubusercontent.com/770d43133153ead0a9b8526e3352ca9933aa60cadcac54fd28aca42c3f71a613/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e312b2d6666363962342e737667)[![PDS Skeleton](https://camo.githubusercontent.com/3c7140ee36205075ed977142f25c29eb1fb7809e9b86a865461fc21776ad1665/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d736b656c65746f6e2d626c75652e7376673f7374796c653d666c6174)](https://github.com/php-pds/skeleton)[![llms.txt](https://camo.githubusercontent.com/78693a04424cf0fbf7cb08afbbcdbef4fbce3d6e1b9cd915d1c2d531b7a0789a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6c6d732e7478742d617661696c61626c652d626c75652e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/78693a04424cf0fbf7cb08afbbcdbef4fbce3d6e1b9cd915d1c2d531b7a0789a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6c6d732e7478742d617661696c61626c652d626c75652e7376673f7374796c653d666c6174)

 [![Llms txt logo](llms-txt-logo.png)](llms-txt-logo.png)

This library supports you in creating, reading, and validating [llms.txt](https://llmstxt.org/) Markdown files via PHP. A good example `llms.txt` file is the [one](https://docs.astral.sh/uv/llms.txt) from the [uv](https://docs.astral.sh/uv/) project.

What's llms.txt?
----------------

[](#whats-llmstxt)

Think of it like `robots.txt` for LLMs. The evolving spec is available over [here](https://llmstxt.org/). For the structure of a `llms.txt` file you can also have a look at this repository's [llms.txt](llms.txt) file.

Installation and usage
----------------------

[](#installation-and-usage)

```
composer require stolt/llms-txt-php
```

### Creating a llms.txt file

[](#creating-a-llmstxt-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')
    ->link((new Link())->urlTitle('Link title')
        ->url('https://link_url')
    );

$llmsTxt = (new LlmsTxt())->title('Test title')
  ->description('Test description')
  ->details('Test details')
  ->addSection($section1) // OR ->addSections([$section1, $section2])
  ->section($section2) // alias method
  ->toString(); // OR ->toFile('/path/to/llmsTxtToBe.md');
```

### Validating and reading a llms.txt file and its parts

[](#validating-and-reading-a-llmstxt-file-and-its-parts)

```
use Stolt\LlmsTxt\LlmsTxt;

$llmsText = (new LlmsTxt())->parse('/path/to/llmsTxt.md'); // OR parse('markdown-string')

if ($llmsText->validate()) {
    $title = $llmsText->getTitle();
    $description = $llmsText->getDescription();
    $details = $llmsText->getDetails();
    $sections = $llmsText->getSections();
}
```

In case you want to get the exact validation errors, you need to call `validate` with the `detailed` flag sat to `true` and than use the `errors()` method like shown below.

```
use Stolt\LlmsTxt\LlmsTxt;

$llmsText = (new LlmsTxt())->parse('/path/to/llmsTxt.md'); // OR parse('markdown-string')

$validationResult = $llmsTxt->validate(true);
if ($validationResult->isValid()) {
    $title = $llmsText->getTitle();
    $description = $llmsText->getDescription();
    $details = $llmsText->getDetails();
    $sections = $llmsText->getSections();
} else {
    $validationErrors = $validationResult->errors();
    // ...
}
```

Tip

To interact with `llms.txt` files from the console, the complement package [llms-txt-php-cli](https://github.com/raphaelstolt/llms-txt-php-cli) might come in handy. The complementary package also includes four AI skills that can be used to interact with `llms.txt` files.

### Inline LLM instructions in HTML

[](#inline-llm-instructions-in-html)

[Vercel](https://vercel.com/) [proposed](https://vercel.com/blog/a-proposal-for-inline-llm-instructions-in-html) a non-formal standard for inlining LLM instructions in HTML, based on the `llms.txt` standard.

```
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')
    ->link((new Link())->urlTitle('Link title')
        ->url('https://link_url')
    );

$llmsTxtContent = (new LlmsTxt())->title('Test title')
  ->description('Test description')
  ->details('Test details')
  ->sections([$section1, $section2])
  ->asScriptTag(); // OR ->toEmbeddedInScriptTag()
```

Value of `$llmsTxtContent`:

```

```

For more usage examples, have a look at the tests i.e. [LlmsTxtTest.php](tests/LlmsTxtTest.php).

### Extract LLM instructions from HTML

[](#extract-llm-instructions-from-html)

```
use Stolt\LlmsTxt\Extractor;

$html =
  string(11) "# first llms.txt content"
  [1]=>
  string(12) "# second llms.txt content"
}
```

To retrieve already parsed `llms.txt` object instances, pass the `parse` flag to the available extraction methods.

Value of `$llmsTxts` when parsed:

```
array(2) {
  [0]=>
  object(Stolt\LlmsTxt\LlmsTxt)#11 (5) {
    ["hasBeenParsed":"Stolt\LlmsTxt\LlmsTxt":private]=>
    bool(true)
    ["title":"Stolt\LlmsTxt\LlmsTxt":private]=>
    string(22) "first llms.txt content"
    ["description":"Stolt\LlmsTxt\LlmsTxt":private]=>
    string(0) ""
    ["details":"Stolt\LlmsTxt\LlmsTxt":private]=>
    string(0) ""
    ["sections":"Stolt\LlmsTxt\LlmsTxt":private]=>
    array(0) {
    }
  }
  [1]=> // ... ommitted for brevity
}
```

### Running tests

[](#running-tests)

```
composer test
```

### License

[](#license)

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

### Changelog

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for more details.

### Contributing

[](#contributing)

Please see [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more details.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance72

Regular maintenance activity

Popularity36

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Recently: every ~12 days

Total

24

Last Release

216d ago

Major Versions

v1.6.3 → v2.0.02025-07-29

v2.1.1 → v3.0.02025-08-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/132faf5713fa951f4263fad02858a62e55c5d832ad775b33e49ba0cda2f2a028?d=identicon)[Raphael Stolt](/maintainers/Raphael%20Stolt)

---

Top Contributors

[![raphaelstolt](https://avatars.githubusercontent.com/u/48225?v=4)](https://github.com/raphaelstolt "raphaelstolt (94 commits)")

---

Tags

documentationlibraryllmsllms-txtllmstxtmarkdownphpportllmsllms-txt

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stolt-llms-txt-php/health.svg)

```
[![Health](https://phpackages.com/badges/stolt-llms-txt-php/health.svg)](https://phpackages.com/packages/stolt-llms-txt-php)
```

###  Alternatives

[nikic/phlexy

Lexing experiments in PHP

162570.9k13](/packages/nikic-phlexy)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23483.5k2](/packages/corveda-php-sandbox)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[bupy7/xml-constructor

The array-like constructor of XML document structure.

1337.9k](/packages/bupy7-xml-constructor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
