2017 © Pedro Peláez
 

library linkify

Converts URLs and email addresses in text into HTML links its extended from Misd\Linify its also support laravel 5

image

nahid/linkify

Converts URLs and email addresses in text into HTML links its extended from Misd\Linify its also support laravel 5

  • Sunday, July 3, 2016
  • by nahid
  • Repository
  • 1 Watchers
  • 9 Stars
  • 17,020 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 2 Versions
  • 24 % Grown

The README.md

Linkify

This a Linkify Laravel 5 supported package. Its converts URLs and email addresses into clickable links. It works on both snippets of HTML (or plain text) and complete HTML pages., (*1)

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

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

Authors

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

Installation

  1. Add Linkify to your dependencies:, (*5)

    // composer.json
    
    {
       // ...
       "require": {
           // ...
           "nahid/linkify": "1.1.*"
       }
    }
  2. Use Composer to download and install Linkify:, (*6)

    $ php composer.phar update Nahid/linkify
  3. open config/app.php and in providers array add this line, (*7)

    Nahid\Linkify\LinkifyServiceProvider::class,
    

    and in aliases array add this line too, (*8)

    'Linkify' => Nahid\Linkify\Facades\Linkify::class,
    
  4. Open terminal and goto your project and run this command, (*9)

    composer dump-autoload
    

Usage

    $text = 'This is my text containing a link to www.example.com.';

    echo Linkify::process($text);

Will output:, (*10)

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

    $linkify = new \Nahid\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:, (*12)

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

Whereas:, (*13)

    $linkify = new \Nahid\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:, (*14)

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

Available options are:, (*15)

attr

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

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

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

    $linkify = new \Nahid\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

03/07 2016

dev-master

9999999-dev https://github.com/nahid/linkify

Converts URLs and email addresses in text into HTML links its extended from Misd\Linify its also support laravel 5

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Nahid Bin Azhar

laravel url link laravel 5 convert email address

16/04 2016

1.0.0

1.0.0.0 https://github.com/nahid/linkify

Converts URLs and email addresses in text into HTML links its extended from Misd\Linify its also support laravel 5

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Nahid Bin Azhar

laravel url link laravel 5 convert email address