misd/linkify-bundle
Symfony bundle integrating the Linkify library to automatically convert plain-text URLs and email addresses into clickable HTML links. Provides a Twig filter and service for linkifying content in templates or PHP code with configurable options.
This is a Symfony2 bundle, not a Laravel package — that distinction drives everything below. misd/linkify-bundle is a thin DI + Twig wrapper around the framework-agnostic misd/linkify library. In a Laravel app you almost never want the bundle; you want the library it wraps and ~15 lines of glue.
Minimal path for a Laravel developer:
composer require misd/linkify
use Misd\Linkify\Linkify;
$linkify = new Linkify();
echo $linkify->process('See https://example.com or mail [email protected]');
// See <a href="https://example.com">https://example.com</a> or ...
Where to look first, in order:
misd/linkify README (the actual behavior lives there, not in the bundle).Linkify::process($text, array $options) — the only API you'll touch day-to-day.DependencyInjection/Configuration.php if you're curious what knobs exist (there are very few).First real use case: turning URLs/emails in user-generated content (comments, forum posts, ticket descriptions, chat transcripts) into anchors before rendering. Bind it once in a service provider and forget it:
// AppServiceProvider::register()
$this->app->singleton(\Misd\Linkify\Linkify::class, fn () => new \Misd\Linkify\Linkify());
Blade directive or a helper. The bundle's Twig |linkify filter has no Laravel equivalent, so add one:
Blade::directive('linkify', fn ($expr) => "<?php echo app(\Misd\Linkify\Linkify::class)->process($expr); ?>");
Or a Str::macro('linkify', ...) if you prefer calling it from presenters and API resources. Pick one and keep it consistent — mixed call sites are how escaping bugs creep in.
Escape first, then linkify. This is the safe ordering:
$safe = e($comment->body);
$html = $linkify->process($safe);
// Blade: {!! $html !!}
The library inserts <a> tags into your string; it is not a sanitizer. If you pass raw user input and then mark the result safe, you've handed attackers an HTML injection primitive.
Options for production links. You'll want target/rel almost immediately:
$linkify->process($text, [
'attr' => ['target' => '_blank', 'rel' => 'nofollow noopener noreferrer'],
]);
Callback for special cases — email obfuscation, internal-link rewriting, or analytics parameters:
$linkify->process($text, [
'callback' => function ($text, $url, $isEmail) {
return $isEmail
? '<a href="#" data-email="'.e($url).'">email</a>'
: '<a href="'.e($url).'" rel="nofollow">'.e($text).'</a>';
},
]);
Order of operations with truncation. If you truncate post bodies, truncate the raw text first, then linkify — otherwise you cut through an <a> tag and produce broken markup. Alternatively, linkify first and truncate with an HTML-aware helper (e.g. HTMLPurifier or a DOM-based truncator).
Symfony context (if you genuinely are on Symfony 2/3). Register the bundle in AppKernel, then use {{ text|linkify }} in Twig or inject the misd_linkify.linkify service. That's the entire surface area — don't expect config depth.
composer require misd/linkify-bundle in Laravel. It pulls Symfony DI/HttpKernel wiring that has nowhere to register. You'll get an inert package and a mess of dependencies. Use misd/linkify directly.mb_* usage) before shipping; there is no maintainer to fix it.<script>alert(1)</script> https://x.test through process() and see what comes out. Do this in a unit test, not in staging.., ,, )), balanced parentheses in Wikipedia URLs, and URLs at end-of-sentence are the classic failure modes. Build a small fixture corpus from your actual content and snapshot-test the output.https://münchen.de or IDN emails, expect misses.mailto: links get scraped. Use the callback option to emit data- attributes and let JS build the mailto, or HTML-entity-encode the address.Cache::remember) rather than recomputing on every render.process() directly in tinker and bisect the input string — don't debug through Blade.Misd\Linkify\Linkify and override the matching methods, or pre/post-process around it.Autolink extension gives you linkification plus a real parser. If you need sanitization anyway, HTMLPurifier's AutoFormat.Linkify does both jobs in one pass. This package is reasonable only when you want exactly one thing: turn bare URLs into anchors, nothing more.How can I help you explore Laravel packages today?