PHPackages                             asika/autolink - 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. asika/autolink

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

asika/autolink
==============

Auto convert url to link anchor.

2.2.0(9mo ago)34454.0k↑31.6%11[2 issues](https://github.com/asika32764/php-autolink/issues)[1 PRs](https://github.com/asika32764/php-autolink/pulls)2MITPHPPHP &gt;=8.2CI passing

Since Jun 13Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/asika32764/php-autolink)[ Packagist](https://packagist.org/packages/asika/autolink)[ Docs](https://github.com/asika32764/php-autolink)[ RSS](/packages/asika-autolink/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (16)Used By (2)

PHP Autolink Library
====================

[](#php-autolink-library)

[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/b48b14fae63dbb48ae62da711f76d1d9a96e141cca2864546baeb4b1cdbbfa35/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6173696b6133323736342f7068702d6175746f6c696e6b2f63692e796d6c3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/b48b14fae63dbb48ae62da711f76d1d9a96e141cca2864546baeb4b1cdbbfa35/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6173696b6133323736342f7068702d6175746f6c696e6b2f63692e796d6c3f7374796c653d666f722d7468652d6261646765)[![Packagist Version](https://camo.githubusercontent.com/fd546970ba29d23c25acc9bed9bc5ebf8446d8ad94347a274f7f20a6919a0687/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6173696b612f6175746f6c696e6b3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/asika/autolink)[![Packagist Downloads](https://camo.githubusercontent.com/2d3fc6704602502f101f4b231a44fdc2550c3f88d5bd6fb582153e50a7ac46d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6173696b612f6175746f6c696e6b3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/asika/autolink)

A library to auto convert URLs to links.

Table of Content
----------------

[](#table-of-content)

- [PHP Autolink Library](#php-autolink-library)
    - [Table of Content](#table-of-content)
    - [Requirement](#requirement)
    - [Installation via Composer](#installation-via-composer)
    - [Getting Started](#getting-started)
    - [Use Autolink Object](#use-autolink-object)
    - [Convert Text](#convert-text)
        - [Add Attributes](#add-attributes)
    - [Convert Email](#convert-email)
    - [Attributes Escaping](#attributes-escaping)
    - [Options](#options)
        - [`textLimit`](#textlimit)
        - [`autoTitle`](#autotitle)
        - [`stripScheme`](#stripscheme)
        - [`escape`](#escape)
        - [`linkNoScheme`](#linknoscheme)
    - [Scheme](#scheme)
    - [Link Builder](#link-builder)

Requirement
-----------

[](#requirement)

- Version 2.1.x require PHP 8.2 or higher.
- Version 2.0.x require PHP 8.0 or higher.
- Version 1.x supports PHP 5.3 to 7.4

Installation via Composer
-------------------------

[](#installation-via-composer)

Add this to composer.json require block.

```
{
    "require": {
        "asika/autolink": "^2.0"
    }
}
```

Getting Started
---------------

[](#getting-started)

This is a quick start to convert URL to link:

```
use Asika\Autolink\AutolinkStatic;

$text = AutolinkStatic::convert($text);
$text = AutolinkStatic::convertEmail($text);
```

Use Autolink Object
-------------------

[](#use-autolink-object)

Create the object:

```
use Asika\Autolink\Autolink;

$autolink = new Autolink();
```

Create with options.

```
use Asika\Autolink\AutolinkOptions;

$options = new AutolinkOptions(
    stripScheme: false,
    textLimit: null,
    autoTitle: false,
    escape: true,
    linkNoScheme: false
);

$schemes = ['http', 'https', 'skype', 'itunes'];

$autolink = new Autolink($options, $schemes);
```

Convert Text
------------

[](#convert-text)

This is an example text:

```
This is Simple URL:
http://www.google.com.tw

This is SSL URL:
https://www.google.com.tw

This is URL with multi-level query:
http://example.com/?foo[1]=a&foo[2]=b
```

We convert all URLs.

```
$text = $autolink->convert($text);
```

Output:

```
This is Simple URL:
http://www.google.com.tw

This is SSL URL:
https://www.google.com.tw

This is URL with multi-level query:
http://example.com/?foo[1]=a&amp;foo[2]=b
```

### Add Attributes

[](#add-attributes)

```
$text = $autolink->convert($text, ['class' => 'center']);
```

All link will add this attributes:

```
This is Simple URL:
http://www.google.com.tw

This is SSL URL:
https://www.google.com.tw
```

Convert Email
-------------

[](#convert-email)

Email url has no scheme, we use anoter method to convert them, and it will add `mailto:` at begin of `href`.

```
$text = $autolink->convertEmail($text);
```

Output

```
foo@example.com
```

Attributes Escaping
-------------------

[](#attributes-escaping)

As `htmlspecialchars()` in PHP 8.1 or higher will escape single quote as default, Autolink will also escape single quote even in 8.0. Use this method to keep all escape behavior same at any PHP versions:

```
$autolink->escape('...');
```

If you want to change the escape behavior, set your custom escape handler:

```
$autolink->setEscapeHandler(fn => ...);
```

Options
-------

[](#options)

### `textLimit`

[](#textlimit)

We can set this option by constructor or setter:

```
$autolink->textLimit(50);

$text = $autolink->convert($text);
```

The link text will be:

```
http://campus.asukademy.com/learning/job/84-fin...

```

Use Your own limit handler by set a callback:

```
$autolink->textLimit(function($url) {
    return substr($url, 0, 50) . '...';
});
```

Or use `\Asika\Autolink\LinkHelper::shorten()` Pretty handler:

```
$autolink->textLimit(function($url) {
    return \Asika\Autolink\Autolink::shortenUrl($url, 15, 6);
});
```

Output:

```
http://campus.asukademy.com/....../84-find-interns......

```

### `autoTitle`

[](#autotitle)

Use AutoTitle to force add title on anchor element.

```
$autolink->autoTitle(true);

$text = $autolink->convert($text);
```

Output:

```
http://www.google.com.tw
```

### `stripScheme`

[](#stripscheme)

Strip Scheme on link text:

```
$autolink->stripScheme(true);

$text = $autolink->convert($text);
```

Output

```
www.google.com.tw
```

### `escape`

[](#escape)

Auto escape URL, default is `true`:

```
$autolink->autoEscape(false);

$text = $autolink->convert($text);

$autolink->autoEscape(true);

$text = $autolink->convert($text);
```

Output

```
http://www.google.com.tw?foo=bar&yoo=baz
http://www.google.com.tw?foo=bar&amp;yoo=baz
```

### `linkNoScheme`

[](#linknoscheme)

Convert URL which no scheme. If you pass `TRUE` to this option, Autolink will use `http` as default scheme, you can also provide your own default scheme.

```
$autolink->linkNoScheme('https');

$text = $autolink->convert('www.google.com.tw');
```

Output

```
www.google.com.tw
```

Scheme
------

[](#scheme)

You can add new scheme to convert URL begin with it, for example: `vnc://example.com`

```
$autolink->addScheme('skype', 'vnc');
```

Default schemes is `http, https, ftp, ftps`.

Link Builder
------------

[](#link-builder)

If you don't want to use `` element as your link, you can set a callback to build link HTML.

```
$autolink->setLinkBuilder(function(string $url, array $attribs) {
    $attribs['src'] = htmlspecialchars($url);

    return \Asika\Autolink\HtmlBuilder::create('img', $attribs, null);
});
```

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance56

Moderate activity, may be stable

Popularity48

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 91.1% 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 ~265 days

Recently: every ~172 days

Total

15

Last Release

283d ago

Major Versions

1.1.2 → 2.0.02022-08-28

PHP version history (3 changes)1.1.0PHP &gt;=5.3

2.0.0PHP &gt;=8.0

2.1.0PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1639206?v=4)[Simon Asika](/maintainers/asika32764)[@asika32764](https://github.com/asika32764)

---

Top Contributors

[![asika32764](https://avatars.githubusercontent.com/u/1639206?v=4)](https://github.com/asika32764 "asika32764 (72 commits)")[![arnt](https://avatars.githubusercontent.com/u/236384?v=4)](https://github.com/arnt "arnt (2 commits)")[![hirasso](https://avatars.githubusercontent.com/u/869813?v=4)](https://github.com/hirasso "hirasso (2 commits)")[![burki](https://avatars.githubusercontent.com/u/464455?v=4)](https://github.com/burki "burki (1 commits)")[![noah-st-amand](https://avatars.githubusercontent.com/u/2590331?v=4)](https://github.com/noah-st-amand "noah-st-amand (1 commits)")[![TimothyBJacobs](https://avatars.githubusercontent.com/u/3460448?v=4)](https://github.com/TimothyBJacobs "TimothyBJacobs (1 commits)")

---

Tags

autolinkphp-autolinkurl-parserlinkLinkifyautolink

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asika-autolink/health.svg)

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

###  Alternatives

[jbroadway/urlify

A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.

6737.4M62](/packages/jbroadway-urlify)[iamcal/lib_autolink

Adds anchors to urls in a text

631.3M3](/packages/iamcal-lib-autolink)[misd/linkify

Converts URLs and email addresses in text into HTML links

1122.9M10](/packages/misd-linkify)[nojimage/twitter-text-php

A library of PHP classes that provide auto-linking and extraction of usernames, lists, hashtags and URLs from tweets.

1241.9M7](/packages/nojimage-twitter-text-php)[shivella/laravel-bitly

Laravel package for generating bitly url

75789.0k1](/packages/shivella-laravel-bitly)[voku/urlify

PHP port of URLify.js from the Django project. Transliterates non-ascii characters for use in URLs.

254.1M7](/packages/voku-urlify)

PHPackages © 2026

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