2017 © Pedro Peláez
 

library linkify

Converts URLs and email addresses in text into HTML links

image

misd/linkify

Converts URLs and email addresses in text into HTML links

  • Thursday, August 17, 2017
  • by thewilkybarkid
  • Repository
  • 7 Watchers
  • 74 Stars
  • 364,408 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 11 Forks
  • 11 Open issues
  • 7 Versions
  • 5 % Grown

The README.md

Linkify

Build Status, (*1)

Converts URLs and email addresses into clickable links. It works on both snippets of HTML (or plain text) and complete HTML pages., (*2)

There are many regex variations shared on the internet for performing this task, but few are robust. Linkify contains a large number of unit tests to counter this., (*3)

It does not cover every possible valid-yet-never-used URLs and email addresses in order to handle 'real world' usage (eg no 'gopher://'). This means, for example, that it copes better with punctuation errors., (*4)

Authors

  • Chris Wilkinson

It uses regex based on John Gruber's Improved Liberal, Accurate Regex Pattern for Matching URLs., (*5)

Installation

composer require misd/linkify, (*6)

Usage

$linkify = new \Misd\Linkify\Linkify();
$text = 'This is my text containing a link to www.example.com.';

echo $linkify->process($text);

Will output:, (*7)

This is my text containing a link to <a href="http://www.example.com">www.example.com</a>.

Options

Options set on the constructor will be applied to all links. Alternatively you can place the options on a method call. The latter will override the former., (*8)

$linkify = new \Misd\Linkify\Linkify(array('attr' => array('class' => 'foo')));
$text = 'This is my text containing a link to www.example.com.';

echo $linkify->process($text);

Will output:, (*9)

This is my text containing a link to <a href="http://www.example.com" class="foo">www.example.com</a>.

Whereas:, (*10)

$linkify = new \Misd\Linkify\Linkify(array('attr' => array('class' => 'foo')));
$text = 'This is my text containing a link to www.example.com.';

echo $linkify->process($text, array('attr' => array('class' => 'bar')));

Will output:, (*11)

This is my text containing a link to <a href="http://www.example.com" class="bar">www.example.com</a>.

Available options are:, (*12)

attr

An associative array of HTML attributes to add to the link. For example:, (*13)

array('attr' => array('class' => 'foo', 'style' => 'font-weight: bold; color: red;')

callback

A closure to call with each url match. The closure will be called for each URL found with three parameters: the url, the caption and a boolean isEmail (if $isEmail is true, then $url is equals to $caption., (*14)

If the callback return a non-null value, this value replace the link in the resulting text. If null is returned, the usual <a href="URL">CAPTION</a> is used., (*15)

$linkify = new \Misd\Linkify\Linkify(array('callback' => function($url, $caption, $isEmail) {
    return '<b>' . $caption . '</b>';
}));
echo $linkify->process('This link will be converted to bold: www.example.com.'));

The Versions

17/08 2017

dev-master

9999999-dev https://github.com/misd-service-development/php-linkify

Converts URLs and email addresses in text into HTML links

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

url link convert email address

17/08 2017

v1.1.4

1.1.4.0 https://github.com/misd-service-development/php-linkify

Converts URLs and email addresses in text into HTML links

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

url link convert email address

18/02 2017

v1.1.3

1.1.3.0 https://github.com/misd-service-development/php-linkify

Converts URLs and email addresses in text into HTML links

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

url link convert email address

12/05 2014

v1.1.2

1.1.2.0 https://github.com/misd-service-development/php-linkify

Converts URLs and email addresses in text into HTML links

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Chris Wilkinson

url link convert email address

02/04 2013

v1.1.1

1.1.1.0 https://github.com/misd-service-development/php-linkify

Converts URLs and email addresses in text into HTML links

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Chris Wilkinson

url link convert email address

07/11 2012

v1.1.0

1.1.0.0 https://github.com/misd-service-development/php-linkify

Converts URLs and email addresses in text into HTML links

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Chris Wilkinson

url link convert email address

08/10 2012

v1.0.0

1.0.0.0 https://github.com/misd-service-development/php-linkify

Converts URLs and email addresses in text into HTML links

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Chris Wilkinson

url link convert email address