PHP code example of madlines / common-autolink

1. Go to this page and download the library: Download madlines/common-autolink 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/ */

    

madlines / common-autolink example snippets




use Madlines\Common\AutoLink\AutoLink;

$input = 'My string containing some urls like www.example.com or smth more fancy like https://www.example.com:8803/foo/bar?lorem=ipsum#dolor/sit/amet';
$output = AutoLink::parse($input);



namespace MyApp\MyBundle\Twig;

use Madlines\Common\AutoLink\AutoLink;

class AutoLinkExtension extends \Twig_Extension
{
    const NAME = 'auto_link_extension';

    /**
     * @return array
     */
    public function getFilters()
    {
        return [
            new \Twig_SimpleFilter('auto_link', [$this, 'autoLink']),
        ];
    }

    /**
     * @param string $text
     * @return string
     */
    public function autoLink($text)
    {
        return AutoLink::parse($text)
    }

    /**
     * @return string
     */
    public function getName()
    {
        return self::NAME;
    }
}