Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Linkify Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  1. The misd/linkify README (the actual behavior lives there, not in the bundle).
  2. Linkify::process($text, array $options) — the only API you'll touch day-to-day.
  3. The bundle's 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());

Implementation Patterns

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.

Gotchas and Tips

  • Do not 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.
  • Abandoned since 2016-08-22, 4 stars, 0 dependents. Treat this as a "vendor a small MIT-licensed class" decision, not an "adopt an ecosystem" one. Audit PHP 8 compatibility (regex and mb_* usage) before shipping; there is no maintainer to fix it.
  • No escaping guarantees. Test explicitly: pass <script>alert(1)</script> https://x.test through process() and see what comes out. Do this in a unit test, not in staging.
  • Boundary detection is imperfect. Trailing punctuation (., ,, )), 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.
  • Internationalized domains and emails are not well handled by a 2016-era ASCII regex. If your audience posts https://münchen.de or IDN emails, expect misses.
  • Email harvesting. Plain mailto: links get scraped. Use the callback option to emit data- attributes and let JS build the mailto, or HTML-entity-encode the address.
  • Performance in lists. Regex over every comment in a 50-item thread is noticeable. Cache the linkified HTML on write (a model accessor + Cache::remember) rather than recomputing on every render.
  • Debugging is bare. No logging, no introspection. When a URL isn't linking, call process() directly in tinker and bisect the input string — don't debug through Blade.
  • Extension points are the callback and subclassing. The bundle exposes almost nothing via config; if you need custom detection rules, extend Misd\Linkify\Linkify and override the matching methods, or pre/post-process around it.
  • Consider the alternatives before committing. If your content is Markdown, League CommonMark's 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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
abbasudo/artisan-route
mirvan/ippanel
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package