Download the PHP package hirasso/autolinker without Composer
On this page you can find all versions of the php package hirasso/autolinker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hirasso/autolinker
More information about hirasso/autolinker
Files in hirasso/autolinker
Package autolinker
Short Description Automatically link URLs and email addresses in a given block of text/HTML 🖇️
License MIT
Informations about the package autolinker
hirasso/php-autolinker
Automatically link URLs and email addresses in a given block of text/HTML 🖇️
Framework-agnostic: pass an HTML fragment, get an HTML fragment back with plain
urls and email addresses turned into links. Wire it into your CMS / framework
yourself (e.g. a WordPress acf/format_value filter).
Requirements
- PHP 8.4+ (uses the new
Dom\HTMLDocumentAPI)
Installation
Usage
Pass a string, get a string back:
Autolinker::link() accepts an HTML fragment, a full (or partial) HTML document
or an existing Dom\HTMLDocument. Only text is linked. Elements where autolinking doesn't make sense (like e.g. button, script, style, svg, noscript, title, textarea, select, pre, code, etc...),
are skipped.
If you pass a full or partial document, only the body's inner HTML is linked;
the doctype, <head>, body attributes, comments and anything wrapping the body
are preserved verbatim:
What gets linked
http://andhttps://urls- Schemeless
www.urls (the href is prefixed withhttps://) - Email addresses (turned into
mailto:links)
Trailing sentence punctuation stays out of the link:
Options
Pass an AutolinkerOptions object as the second argument to configure the output:
AutolinkerOptions is immutable and every option is optional, so you only need
to set the ones you want to change. stripScheme only affects the visible text,
never the href:
Use postProcess to decorate the generated anchors — e.g. mark external links,
add classes or target / rel attributes. It receives every anchor this
library creates and never touches links that were already in your HTML.
Working with a Dom\HTMLDocument
If you already have a document, pass it directly. It is modified by reference and returned as-is (rather than serialized back to a string):
License
MIT © Rasso Hilber