PHPackages                             youthweb/urllinker - 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. youthweb/urllinker

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

youthweb/urllinker
==================

Autolink URLs in text or html

2.1.0(10mo ago)4449.4k—0.6%[1 issues](https://github.com/Art4/urllinker/issues)1GPL-3.0-or-laterPHPPHP ^8.1CI passing

Since Sep 5Pushed 10mo ago7 watchersCompare

[ Source](https://github.com/Art4/urllinker)[ Packagist](https://packagist.org/packages/youthweb/urllinker)[ Docs](https://github.com/Art4/urllinker)[ RSS](/packages/youthweb-urllinker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (14)Used By (1)

UrlLinker
=========

[](#urllinker)

[![Latest Version](https://camo.githubusercontent.com/260e85e9fe684b6d0aebe5514192ab3dbf67ff96531e9bff023a215616632282/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f417274342f75726c6c696e6b65722e737667)](https://github.com/Art4/urllinker/releases)[![Software License](https://camo.githubusercontent.com/6f2b03e518f71117284f01a8bf089395fa6c9400661b197d9b9be1919550b944/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c332d627269676874677265656e2e737667)](LICENSE.md)[![Build Status](https://github.com/Art4/urllinker/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/Art4/urllinker/actions)[![codecov](https://camo.githubusercontent.com/5d23aa61658ced3f364e6329f3b8208ad8152d1a873bac53fdcf51a9a75ebba1/68747470733a2f2f636f6465636f762e696f2f67682f417274342f75726c6c696e6b65722f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d3079677a536776556655)](https://codecov.io/gh/Art4/urllinker)[![Total Downloads](https://camo.githubusercontent.com/06dc17670c28393807728fb35902fc509b6d2b156d97454593445305423e1500/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796f7574687765622f75726c6c696e6b65722e737667)](https://packagist.org/packages/youthweb/urllinker)

UrlLinker converts any web addresses in plain text into HTML hyperlinks.

This is a maintained fork of the great work of [Kwi\\UrlLinker](https://github.com/kwi-dk/UrlLinker), formerly on [Bitbucket](https://bitbucket.org/kwi/urllinker).

Install
-------

[](#install)

Via Composer

```
$ composer require youthweb/urllinker
```

> Note: On 2025-07-17 the repository was moved from  to , but the packagist name was kept for convenience.

Usage
-----

[](#usage)

```
$urlLinker = new Youthweb\UrlLinker\UrlLinker();

$linkedText = $urlLinker->linkUrlsAndEscapeHtml($text);

$linkedText = $urlLinker->linkUrlsInTrustedHtml($html);
```

You can optional configure different options for parsing URLs by passing them to `UrlLinker::__construct()`:

```
$config = [
    // Ftp addresses like "ftp://example.com" will be allowed, default false
    'allowFtpAddresses' => true,

    // Uppercase URL schemes like "HTTP://exmaple.com" will be allowed:
    'allowUpperCaseUrlSchemes' => true,

    // Add a Closure to modify the way the urls will be linked:
    'htmlLinkCreator' => function(string $url, string $content): string
    {
        return '' . $content . '';
    },

    // ..or add a callable as a Closure to modify the way the urls will be linked:
    'htmlLinkCreator' => [$class, 'linkCreator'](...),

    // Add a Closure to modify the way the emails will be linked:
    'emailLinkCreator' => function(string $email, string $content): string
    {
        return '' . $content . '';
    },

    // ... or add a callable as a Closure to modify the way the emails will be linked:
    'emailLinkCreator' => \Closure::fromCallable('callableFunction'),

    // ... or you can also disable the links for email with a closure:
    'emailLinkCreator' => fn (string $email, string $content): string => $email,

    // You can customize the recognizable Top Level Domains:
    'validTlds' => ['.localhost' => true],
];

$urlLinker = new Youthweb\UrlLinker\UrlLinker($config);
```

Recognized addresses
--------------------

[](#recognized-addresses)

- Web addresses
    - Recognized URL schemes: "http" and "https"
        - The `http://` prefix is optional.
        - Support for additional schemes, e.g. "ftp", can easily be added by setting `allowFtpAddresses` to `true`.
        - The scheme must be written in lower case. This requirement can be lifted by setting `allowUpperCaseUrlSchemes` to `true`.
    - Hosts may be specified using domain names or IPv4 addresses.
        - IPv6 addresses are not supported.
    - Port numbers are allowed.
    - Internationalized Resource Identifiers (IRIs) are allowed. Note that the job of converting IRIs to URIs is left to the user's browser.
    - To reduce false positives, UrlLinker verifies that the top-level domain is on the official IANA list of valid TLDs.
        - UrlLinker is updated from time to time as the TLD list is expanded.
        - In the future, this approach may collapse under ICANN's ill-advised new policy of selling arbitrary TLDs for large amounts of cash, but for now it is an effective method of rejecting invalid URLs.
        - Internationalized *top-level* domain names must be written in Punycode in order to be recognized.
        - If you want to support only some specific TLD you can set them with `validTlds` e.g. `['.com' => true, '.net' => true]`.
        - If you need to support unqualified domain names, such as `localhost`, you can also set them with `['.localhost' => true]` in `validTlds`.
- Email addresses
    - Supports the full range of commonly used address formats, including "plus addresses" (as popularized by Gmail).
    - Does not recognized the more obscure address variants that are allowed by the RFCs but never seen in practice.
    - Simplistic spam protection: The at-sign is converted to a HTML entity, foiling naive email address harvesters.
    - If you don't want to link emails you can set closure that simply returns the raw email with a closure `function($email, $content) { return $email; }` in `emailLinkCreator`.
- Addresses are recognized correctly in normal sentence contexts. For instance, in "Visit stackoverflow.com.", the final period is not part of the URL.
- User input is properly sanitized to prevent [cross-site scripting](http://en.wikipedia.org/wiki/Cross-site_scripting) (XSS), and ampersands in URLs are [correctly escaped](http://www.htmlhelp.com/tools/validator/problems.html#amp) as `&amp;` (this does not apply to the `linkUrlsInTrustedHtml()` function, which assumes its input to be valid HTML).

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Tests
-----

[](#tests)

Unit tests are written using [PHPUnit](https://phpunit.de).

```
$ phpunit
```

Contributing
------------

[](#contributing)

Please feel free to submit bugs or to fork and sending Pull Requests. This project follows [Semantic Versioning 2](http://semver.org) and [PER Coding Style 3.0](https://www.php-fig.org/per/coding-style/).

License
-------

[](#license)

GPL3. Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance50

Moderate activity, may be stable

Popularity39

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 78.3% 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 ~405 days

Recently: every ~399 days

Total

9

Last Release

301d ago

Major Versions

1.5.1 → 2.0.02022-12-14

PHP version history (5 changes)1.0.0PHP &gt;=5.6

1.1.0PHP ^5.6 || ^7.0

1.3.0PHP ^7.2

1.4.0PHP ^7.4 || ^8.0

2.1.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad0c0fa748422ad817c4124a06618a1e655995502be8d6f03d699f38c0d56b0?d=identicon)[Art4](/maintainers/Art4)

---

Top Contributors

[![Art4](https://avatars.githubusercontent.com/u/2162994?v=4)](https://github.com/Art4 "Art4 (166 commits)")[![kwi-dk](https://avatars.githubusercontent.com/u/1167359?v=4)](https://github.com/kwi-dk "kwi-dk (23 commits)")[![MacDada](https://avatars.githubusercontent.com/u/136261?v=4)](https://github.com/MacDada "MacDada (19 commits)")[![ishyevandro](https://avatars.githubusercontent.com/u/1781740?v=4)](https://github.com/ishyevandro "ishyevandro (3 commits)")[![Xesau](https://avatars.githubusercontent.com/u/7915413?v=4)](https://github.com/Xesau "Xesau (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/youthweb-urllinker/health.svg)

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

###  Alternatives

[raiym/instagram-php-scraper

Instagram PHP Scraper. Get account information, photos and videos without any authorization

3.3k1.2M6](/packages/raiym-instagram-php-scraper)[devster/ubench

Micro PHP library for benchmarking

5701.0M29](/packages/devster-ubench)[msp/devtools

222629.1k2](/packages/msp-devtools)[eusonlito/laravel-meta

A package to manage Header Meta Tags

196525.1k2](/packages/eusonlito-laravel-meta)[geniusts/hijri-dates

PHP library to convert Gregorian date to Hijri date and vice versa

104334.3k9](/packages/geniusts-hijri-dates)[discoverydesign/filament-gaze

See who's viewing a resource in Filament PHP.

17473.7k](/packages/discoverydesign-filament-gaze)

PHPackages © 2026

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