PHP code example of asika / autolink

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

    

asika / autolink example snippets


use Asika\Autolink\AutolinkStatic;

$text = AutolinkStatic::convert($text);
$text = AutolinkStatic::convertEmail($text);

use Asika\Autolink\Autolink;

$autolink = new Autolink();

$options = [
    'strip_scheme' => false,
    'text_limit' => false,
    'auto_title' => false,
    'escape' => true,
    'link_no_scheme' => false
];

$schemes = ['http', 'https', 'skype', 'itunes'];

$autolink = new Autolink($options, $schemes);

$text = $autolink->convert($text);

$text = $autolink->convert($text, ['class' => 'center']);

This is Simple URL:
<a href="http://www.google.com.tw" class="center">http://www.google.com.tw</a>

This is SSL URL:
<a href="https://www.google.com.tw" class="center">https://www.google.com.tw</a>

$text = $aurolink->convertEmail($text);

$auitolink->textLimit(50);

$text = $autolink->convert($text);

$auitolink->textLimit(function($url) {
    return substr($url, 0, 50) . '...';
});

$auitolink->textLimit(function($url) {
    return \Asika\Autolink\Autolink::shortenUrl($url, 15, 6);
});

$autolink->autoTitle(true);

$text = $autolink->convert($text);

$auitolink->stripScheme(true);

$text = $autolink->convert($text);

$auitolink->autoEscape(false);

$text = $autolink->convert($text);

$auitolink->autoEscape(true);

$text = $autolink->convert($text);

$auitolink->linkNoScheme('https');

$text = $autolink->convert('www.google.com.tw');

$autolink->addScheme('skype', 'vnc');

$autolink->setLinkBuilder(function(string $url, array $attribs) {
    $attribs['src'] = htmlspecialchars($url);

    return \Asika\Autolink\HtmlBuilder::create('img', $attribs, null);
});