2017 © Pedro Peláez
 

library link-finder

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.

image

yarri/link-finder

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.

  • Monday, May 14, 2018
  • by yarri
  • Repository
  • 1 Watchers
  • 3 Stars
  • 3,258 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 3 % Grown

The README.md

LinkFinder

Build Status Downloads Codacy Badge, (*1)

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., (*2)

Usage

$text = '
  Welcome at www.example.com!
  Contact us on info@example.com.
';

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

// Welcome at <a href="https://www.example.com/">www.example.com</a>!
// Contact us on <a href="mailto:info@example.com">info@example.com</a>.

Extra attributes for <a> and <a href="mailto:..."> elements can be specified in options:, (*3)

$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="https://www.example.com/" target="_blank" rel="nofollow">www.example.com</a>!
// Contact us on <a class="external-email" href="mailto:info@example.com">info@example.com</a>.

Escaping of HTML entities is enabled by default:, (*4)

$text = '
  Find more at
  <http://www.ourstore.com/>
';

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

// Find more at
// &lt;<a href="http://www.ourstore.com/">http://www.ourstore.com/</a>&gt;

Creating missing links on URLs or emails in a HTML document:, (*5)

$html_document = '


Visit Cesky Krumlov or Prague.eu. , (*6)

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

// Visit Cesky Krumlov or Prague.eu. // , (*7)

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

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:, (*9)

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

// or

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

If no protocol is specified in a future link (e.g. www.example.com), should LinkFinder prefer https over http? It can be set by the option prefer_https. The default value is true. There is also a constant LINK_FINDER_PREFER_HTTPS to change the default behaviour in the global scope., (*10)

If prefer_https is set to false, a list of secured websites can be specified in the option secured_websites:, (*11)

$lf = new LinkFinder([
  "prefer_https" => false,
  "secured_websites" => [
    "example.com",
    "webmail.example.com"
  ]
]);
echo $lf->process('Please, sign in at example.com/login/ or webmail.example.com');

// Please, sign in at <a href="https://example.com/login/">example.com/login/</a> or <a href="https://webmail.example.com">webmail.example.com</a>

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

Long URLs shortening

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

https://venturebeat.com/2018/05/01/donkey-kong-country-tropical-freeze-review-a-funky-fresh-switch-update/

will be converted to:, (*14)

<a href="https://venturebeat.com/2018/05/01/donkey-kong-country-tropical-freeze-review-a-funky-fresh-switch-update/">https://venturebeat.com/2018/05/01/donkey-kong-country-tropica...</a>

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

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

Installation

Just use the Composer:, (*16)

composer require yarri/link-finder

Testing

The LinkFinder is tested automatically using Travis CI in PHP 5.6 to PHP 8.4., (*17)

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

Install required dependencies for development:, (*19)

composer update --dev

Run tests:, (*20)

cd test
../vendor/bin/run_unit_tests

License

LinkFinder is free software distributed under the terms of the MIT license, (*21)

The Versions

14/05 2018

dev-master

9999999-dev https://github.com/yarri/LinkFinder

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.

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

The Development Requires

email url link urlizer e-mail urlize

06/04 2018

v2.3

2.3.0.0 https://github.com/yarri/LinkFinder

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.

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

The Development Requires

email url link urlizer e-mail urlize

08/10 2017

v2.2.1

2.2.1.0 https://github.com/yarri/LinkFinder

In a plain text document searches for URLs and emails and makes them clickable

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

email url link urlizer e-mail urlize

05/10 2017

v2.2

2.2.0.0 https://github.com/yarri/LinkFinder

In a plain text document searches for URLs and emails and makes them clickable

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

email url link urlizer e-mail urlize

06/06 2017

v2.1.1

2.1.1.0 https://github.com/yarri/LinkFinder

In a plain text document searches for URLs and emails and makes them clickable

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

email url link urlizer e-mail urlize

01/04 2017

v2.1

2.1.0.0 https://github.com/yarri/LinkFinder

In a plain text document searches for URLs and emails and makes them clickable

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

email url link urlizer e-mail urlize

15/03 2016

v2.0

2.0.0.0 https://github.com/yarri/LinkFinder

In a plain text document searches for URLs and emails and makes them clickable

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

email url link e-mail

13/03 2016

v1.0

1.0.0.0 https://github.com/yarri/LinkFinder

In a plain text document searches for URLs and emails and makes them clickable

  Sources   Download

MIT

The Requires

  • php >=5.0.0

 

email url link e-mail