Skip to content
Switch branches/tags


Build Status Downloads Codacy Badge

In a plain text document the LinkFinder searches for URLs and email addresses and makes them clickable, in a HTML document searches for missing links and makes them clickable too.


$text = '
  Welcome at!
  Contact us on

$lf = new LinkFinder();
echo $lf->process($text);

// Welcome at <a href=""></a>!
// Contact us on <a href=""></a>.

Extra attributes for <a> and <a href="mailto:..."> elements can be specified in options:

$lf = new LinkFinder([
  "attrs" => ["class" => "external-link", "target" => "_blank", "rel" => "nofollow"],
  "mailto_attrs" => ["class" => "external-email"]
echo $lf->process($text);

// Welcome at <a class="external-link" href="" target="_blank" rel="nofollow"></a>!
// Contact us on <a class="external-email" href=""></a>.

Escaping of HTML entities is enabled by default:

$text = '
  Find more at

$lf = new LinkFinder();
echo $lf->process($text);

// Find more at
// &lt;<a href=""></a>&gt;

Creating missing links on URLs or emails in a HTML document:

$html_document = '
    Visit <a href="">Cesky Krumlov</a> or

$lf = new LinkFinder();
echo $lf->processHtml($html_document);

// <p>
//   Visit <a href="">Cesky Krumlov</a> or <a href=""></a>.
// </p>

Method $lf->processHtml() is actually an alias for $lf->process($html_document,["escape_html_entities" => false]).

In case of processing a HTML text, the LinkFinder doesn't create links in headlines (<h1>, <h2>, ...) by default. It can be overridden by the option avoid_headlines:

echo $lf->processHtml($html_document,["avoid_headlines" => false]);

// or

$lf = new LinkFinder(["avoid_headlines" => false]);
echo $lf->processHtml($html_document);

List of secured websites can be specified in the options:

$lf = new LinkFinder([
  "secured_websites" => [
echo $lf->process('Please, sign in at or');

// Please, sign in at <a href=""></a> or <a href=""></a>

If the secured_websites option is omitted and https protocol is active, the current HTTP host ($_SERVER["HTTP_HOST"]) will be added automatically.

Long URLs shortening

Long URLs are automatically shortened to a maximum of 70 characters. For example, the following URL:

will be converted to:

<a href=""></a>

If the shortening is not desired behaviour, option shorten_long_urls should be set to false:

$lf = new LinkFinder(["shorten_long_urls" => false]);


Just use the Composer:

composer require yarri/link-finder


The LinkFinder is tested automatically using Travis CI in PHP 5.3 to PHP 8.0.

For the tests execution, the package atk14/tester is used. It is just a wrapping script for phpunit/phpunit.

Install required dependencies for development:

composer update --dev

Run tests:

cd test


LinkFinder is free software distributed under the terms of the MIT license


Converts non-clickable URLs and email addresses in text (plain or HTML) into clickable HTML links




No packages published