Download the PHP package stolt/llms-txt-php without Composer
On this page you can find all versions of the php package stolt/llms-txt-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package llms-txt-php
llms-txt-php
A PHP library for creating, parsing, validating, discovering, and expanding /llms.txt files.
Build and consume machine-readable Markdown context for LLMs and AI agents with a focused PHP API and no Composer runtime dependencies.
Why llms-txt-php?
llms.txt is an emerging Markdown-based convention for providing LLMs and AI agents with a concise, structured overview of a website, project, or documentation set.
llms-txt-php gives PHP applications one API for working with that format:
- Create and serialize
llms.txtdocuments. - Parse local files, URLs, or Markdown strings.
- Validate required and recommended document elements.
- Inspect validation errors and warnings.
- Preserve meaningful Markdown details and whitespace while parsing.
- Discover
llms.txtand Markdown resources using the specification's link relations and URL conventions. - Expand linked documents into LLM context or
llms-full.txt. - Embed
llms.txtcontent in HTML. - Extract embedded
text/llms.txtblocks from HTML. - Work with the conventional
Optionalsection without treating it as mechanically special. - Provide custom fetchers for tests and applications that already have an HTTP client.
For the current specification, see llmstxt.org and the AnswerDotAI/llms-txt repository.
Installation
Install the package with Composer:
Quick start
Create a llms.txt
The generated document follows the familiar llms.txt structure:
Write the document directly to a file with toFile():
Parse and read
Parse a file or Markdown string with LlmsTxt:
The parser can also be used directly when you want a focused parsing API:
Parsing preserves the Markdown of the details content, including its meaningful line and paragraph structure. Transport-level differences such as a UTF-8 BOM and CRLF/CR line endings are normalized.
Validate
The specification requires a title. The description, details, and file lists are recommended.
For a simple validity check:
For detailed errors and warnings:
Use errors() for validation errors and warnings() for recommended elements that are missing.
The Optional section
The second version of the specification no longer gives the Optional section mechanical semantics. It remains a convention for secondary links.
optional() and getOptional() provide direct access without requiring callers to know the section name:
The section is named Optional automatically. Setting it replaces an existing Optional section.
The accessor also works with parsed documents.
Discovery
Version two of the specification introduced link relations that allow agents to discover Markdown representations and the llms.txt file covering a page.
Discovery supports:
rel="alternate" type="text/markdown"rel="describedby"- HTML
<link>elements - HTTP
Linkheaders - Markdown URL conventions
- Finding the most specific
llms.txtcovering a page
Generate discovery links
The generated HTML is:
The generated header value can be passed directly to PHP's header() function:
Read discovery links
Resolve Markdown and covering URLs
A page can expose its Markdown representation by appending .md or replacing its extension with .md:
A llms.txt file covers pages below its path. The most specific covering file wins:
Combine discovery and parsing
Discovery locates resources while LlmsTxt parses them.
For example, an application can follow a describedby relation and parse the discovered document:
When serving pages, the same API can be used to announce the covering llms.txt together with the page's Markdown representation:
Expand into LLM context
Linked documents can be expanded into an XML LLM context file.
By default, all sections are expanded. Pass true to skip the conventional Optional section:
Custom fetchers
The default fetcher reads local files and otherwise uses PHP streams.
Pass a callable when you want to use a custom HTTP client, provide fixtures in tests, or control how linked documents are resolved:
The same fetcher approach is available when generating llms-full.txt.
Generate llms-full.txt
Linked documents can also be expanded into a Markdown llms-full.txt document.
The generated document keeps the llms.txt header and expands each link into a ### block containing its details, source URL, and fetched document:
Skip the conventional Optional section with:
A custom fetcher can be supplied as the second argument, just like with toLlmContext().
Inline llms.txt in HTML
The library can embed llms.txt content in HTML using a text/llms.txt script element.
The result has the following form:
toEmbeddedInScriptTag() is available as an alias.
Extract llms.txt from HTML
Use Extractor to retrieve text/llms.txt blocks from HTML:
The result is an array of extracted Markdown strings:
You can also extract from a file:
Pass the parse flag when you want LlmsTxt objects instead of strings:
API overview
LlmsTxt
The main document API:
title()description()details()addSection()addSections()section()sections()optional()getOptional()parse()toString()toFile()validate()getTitle()getDescription()getDetails()getSections()toLlmContext()toLlmContextFile()toFull()toFullFile()asScriptTag()toEmbeddedInScriptTag()
Section
Use Section to group links:
Link
Use Link to represent a Markdown file-list entry:
Discovery
Use Discovery for llms.txt discovery and Markdown URL resolution:
asLinkElements()asLinkHeader()describedByUrls()describedByUrlsFromHeader()markdownAlternates()markdownAlternatesFromHeader()markdownUrls()coveringUrls()coveringUrl()
Extractor
Use Extractor to extract embedded text/llms.txt blocks:
extractFromHtml()extractFromFile()
LlmsTxtParser
Use LlmsTxtParser when you need the parser directly:
parse()parseFile()
CLI
For command-line workflows, use the complementary stolt/llms-txt-php-cli package.
Install it as a development dependency:
The CLI currently provides commands for:
- validating
llms.txtfiles - checking links
- inspecting metadata
- creating an initial
llms.txt - rendering
llms.txt - listing included AI skills
See the CLI repository for installation and usage details.
Examples and tests
The test suite contains additional usage examples and documents edge cases that are important when parsing and serializing llms.txt.
For implementation-level examples, see the tests directory.
Alternative libraries
If you are working in a Laravel application, you may also want to look at laravel-llms-txt.
AI disclaimer
This package is developed with the assistance of Artificial Intelligence (AI). AI tools are used throughout the development process, including code generation, documentation, testing, and maintenance.
While reasonable care is taken to review and validate AI-generated contributions, AI-generated code is not inherently correct, secure, or free of defects. All contributions remain subject to human review and project quality standards.
As with any software, use this package at your own risk. No guarantee is made regarding its fitness for a particular purpose, and the maintainers assume no liability for damages resulting from its use.
License
This library is licensed under the MIT license. Please see LICENSE.md for more details.
Changelog
All noteworthy changes are documented in the CHANGELOG.md.
Contributing
If you're considering contributing to this library, have a look at this repository's CONTRIBUTING.md for more advice.
All versions of llms-txt-php with dependencies
ext-dom Version *
ext-libxml Version *