PHPackages                             hirasso/autolinker - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hirasso/autolinker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hirasso/autolinker
==================

Automatically link URLs and email addresses in a given block of text/HTML 🖇️

v0.0.1(1mo ago)00[1 PRs](https://github.com/hirasso/php-autolinker/pulls)MITPHPPHP ^8.4 | ^8.5CI passing

Since Jul 11Pushed 1mo agoCompare

[ Source](https://github.com/hirasso/php-autolinker)[ Packagist](https://packagist.org/packages/hirasso/autolinker)[ GitHub Sponsors](https://github.com/hirasso)[ RSS](/packages/hirasso-autolinker/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (4)Versions (4)Used By (0)

hirasso/php-autolinker
======================

[](#hirassophp-autolinker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/16e652f0acacbbac6a9d6baa887ab4aaa1c98f59931618fd73d39fbca1bc077a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6869726173736f2f6175746f6c696e6b65723f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465)](https://packagist.org/packages/hirasso/autolinker)[![Test Status](https://camo.githubusercontent.com/a03bfc5f022167254bc3e6f28779959d7b1ea5ad0257d09c8dfbec2a16e5e441/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6869726173736f2f7068702d6175746f6c696e6b65722f63692e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d7465737473)](https://github.com/hirasso/php-autolinker/actions/workflows/ci.yml)[![Code Coverage](https://camo.githubusercontent.com/e3ecceede2220adc43c904e48cf8401c4f9b6498cb49eb37201b782832215ff6/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6869726173736f2f7068702d6175746f6c696e6b65723f7374796c653d666c61742d737175617265266c6f676f3d636f6465636f76266c6f676f436f6c6f723d7768697465266c6162656c3d636f766572616765253230253238776861746576657225323074686174253230656e7461696c73253239)](https://app.codecov.io/gh/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
------------

[](#requirements)

- PHP 8.4+ (uses the new `Dom\HTMLDocument` API)

Installation
------------

[](#installation)

```
composer require hirasso/autolinker
```

Usage
-----

[](#usage)

Pass a string, get a string back:

```
use Hirasso\Autolinker\Autolinker;

echo Autolinker::link('Visit https://example.com or mail me@example.com');
// Visit example.com
// or mail me@example.com
```

`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, ``, body attributes, comments and anything wrapping the body are preserved verbatim:

```
echo Autolinker::link(
    't'
    . 'Visit https://example.com'
);
// t
// Visit example.com
```

### What gets linked

[](#what-gets-linked)

- `http://` and `https://` urls
- Schemeless `www.` urls (the href is prefixed with `https://`)
- Email addresses (turned into `mailto:` links)

Trailing sentence punctuation stays out of the link:

```
echo Autolinker::link('See https://example.com.');
// See example.com.
```

### Options

[](#options)

Pass an `AutolinkerOptions` object as the second argument to configure the output:

```
use Dom\HTMLElement;
use Hirasso\Autolinker\Autolinker;
use Hirasso\Autolinker\AutolinkerOptions;

echo Autolinker::link($html, new AutolinkerOptions(
    urls: true,          // link urls (default: true)
    emails: true,        // link emails (default: true)
    stripScheme: true,   // strip the scheme from link texts (default: true)
    truncateText: 50,    // truncate link texts, ellipsis included; 0 disables (default: 50)
    postProcess: function (HTMLElement $a) {
        // called for each anchor this library creates
        $a->setAttribute('rel', 'noopener');
    },
));
```

`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`:

```
echo Autolinker::link('https://example.com/path');
// example.com/path

echo Autolinker::link('https://example.com/path', new AutolinkerOptions(stripScheme: false));
// https://example.com/path
```

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`

[](#working-with-a-domhtmldocument)

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):

```
use Dom\HTMLDocument;
use Hirasso\Autolinker\Autolinker;

$doc = HTMLDocument::createFromString($html, LIBXML_NOERROR);
Autolinker::link($doc); // $doc is now mutated in place
```

License
-------

[](#license)

MIT © [Rasso Hilber](https://rassohilber.com)

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance92

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92% 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

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/be24778ed8b5f77f16e6e0f984b51d209f5a4588f6673ea4bc3b8b1a6e1083b2?d=identicon)[hirasso](/maintainers/hirasso)

---

Top Contributors

[![hirasso](https://avatars.githubusercontent.com/u/869813?v=4)](https://github.com/hirasso "hirasso (23 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hirasso-autolinker/health.svg)

```
[![Health](https://phpackages.com/badges/hirasso-autolinker/health.svg)](https://phpackages.com/packages/hirasso-autolinker)
```

###  Alternatives

[kx1000/kwota-slownie

Kwota słownie

1019.9k1](/packages/kx1000-kwota-slownie)

PHPackages © 2026

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