stolt/llms-txt-php
Composer 安装命令:
composer require stolt/llms-txt-php
包简介
A library for writing, reading, and validating llms.txt Markdown files.
README 文档
README
This library supports you in creating, reading, and validating 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.
For the structure of a llms.txt file you can also have a look at this repository's llms.txt file.
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') ->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
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 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
Vercel proposed 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:
<script type="text/llms.txt"> <!-- programmatically assembled llms.txt content --> </script>
For more usage examples, have a look at the tests i.e. LlmsTxtTest.php.
Extract LLM instructions from HTML
use Stolt\LlmsTxt\Extractor; $html = <<<HTML <html> <body> <script type="text/llms.txt"># first llms.txt content</script> Some other content. <p>And some more content.</p> <br /> <script type="text/llms.txt"># second llms.txt content</script> </body> </html> HTML; $llmsTxts = (new Extractor())->extractFromHtml($html); // OR ->extractFromFile('/path/to/file.html')
Value of $llmsTxts:
array(2) { [0]=> 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
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.
stolt/llms-txt-php 适用场景与选型建议
stolt/llms-txt-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21.65k 次下载、GitHub Stars 达 26, 最近一次更新时间为 2025 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「port」 「llms」 「llms-txt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stolt/llms-txt-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stolt/llms-txt-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stolt/llms-txt-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package for connecting to all Iraninan payment gateways
Professional SEO/AI indexing + Sitemap (index) + RSS + News/Image/Video sitemaps for CodeIgniter 4
Get information about the current HTTP request
LLM-friendly single-file documentation template for phpDocumentor
Documentation generator next to the code for large and small php projects
Library that defines hexagonal-design based policies
统计信息
- 总下载量: 21.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 26
- 点击次数: 30
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-25
