PHP code example of taylornetwork / linkify

1. Go to this page and download the library: Download taylornetwork/linkify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

taylornetwork / linkify example snippets


'This text has a link https://github.com/taylornetwork/linkify and also another one https://google.com'

'This text has a link [github.com](https://github.com/taylornetwork/linkify) and also another one [google.com](https://google.com)'
 
// OR 
 
'This text has a link <a href="https://github.com/taylornetwork/linkify">github.com</a> and also another one <a href="https://google.com">google.com</a>'

use TaylorNetwork\Linkify\Linkify;

$text = 'This has a link. https://google.com';

$linkify = new Linkify;
$linkify->parse($text);

use TaylorNetwork\Linkify\Linkify;

$text = 'This has a link. https://google.com';

Linkify::instance()->parse($text);

use TaylorNetwork\Linkify\Linkify;

$text = 'This has a link. https://google.com';

$linkify = new Linkify;
$linkify->setConfig('convertTo', Linkify::ConvertHTML);
$linkify->parse($text);

use TaylorNetwork\Linkify\Linkify;

$text = 'This has a link. https://google.com';

Linkify::instance()->setConfig('convertTo', Linkify::ConvertHTML)->parse($text);

use TaylorNetwork\Linkify\MakesLinks;

class DummyClass
{
	use MakesLinks;
	
	protected $text = 'This has a link. https://google.com';
	
	public function getParsedText()
	{
		return $this->linkify($this->text);
	}
}

use TaylorNetwork\Linkify\MakesLinks;
use TaylorNetwork\Linkify\Linkify;

class DummyClass
{
	use MakesLinks;
	
	protected $text = 'This has a link. https://google.com';
	
	public function getParsedText()
	{
		return $this->linkify($this->text);
	}
	
	public function linkifyConfig(&$linkify)
	{
		$linkify->setConfig('convertTo', Linkify::ConvertHTML);
		$linkify->setConfig('linkAttributes', [
			'class' => 'btn-link'
		]);
	}
}

use TaylorNetwork\Linkify\MakesLinks;
use TaylorNetwork\Linkify\Linkify;

class DummyClass
{
	use MakesLinks;
	
	protected $text = 'This has a link. https://google.com';
	
	public function getParsedText()
	{
		return $this->linkify($this->text);
	}
	
	public function linkifyConfig(&$linkify)
	{
		$linkify->setConfig('convertTo', Linkify::ConvertCustom);
	}
	
	public function linkifyCustomParse(string $caption, string $url) 
	{
		return '=>' . $caption . '<=#' . $url . '#';
	}
}

'convertTo' => Linkify::ConvertMarkdown, // Converts to markdown links
// OR
'convertTo' => Linkify::ConvertHTML,     // Converts to <a> links
// OR
'convertTo' => Linkify::ConvertCustom,   // Your own custom callback

'linkAttributes' => [
	'target' => '_blank',
	'class' => 'btn-link',
],

// Link is already formatted, by user, or another package, etc.
$text = 'Link: [link](https://google.com)';

Linkify::instance()->parse($text);

// Returns

// If 'checkForExistingFormatting' is true
'Link: [link](https://google.com)'

// If 'checkForExistingFormatting' is false
'Link: [link]([google.com](https://google.com))'

'customCallback' => function ($caption, $url) {
	return '{' . $caption . '}#' . $url . '#';
},
bash
$ php artisan vendor:publish --provider="TaylorNetwork\Linkify\LinkifyServiceProvider"