- How do I install and use vstelmakh/url-highlight in a Laravel application?
- Install it with Composer using composer require vstelmakh/url-highlight. In Laravel, bind the Highlighter interface as a singleton in a service provider and inject it into controllers, services, jobs, or a custom Blade directive. Call highlight() to replace URLs with links or find() to extract matches. Avoid static calls so the highlighter remains easy to configure and test.
- Does vstelmakh/url-highlight support Laravel 10 or 11, and which PHP version is required?
- The package is framework-agnostic, so Laravel support depends mainly on your Laravel version supporting the required PHP runtime. Version 4 requires PHP 8.4 minimum, which is the biggest adoption gate for Laravel applications still on PHP 8.1 through 8.3. Audit app, CI, queue, and container PHP versions before planning the upgrade.
- How do I highlight URLs in a Blade template with vstelmakh/url-highlight?
- Create a Blade directive or view helper that resolves the Highlighter from Laravel's container and calls highlight() with an explicit Format. Use Format::Html for trusted CMS content and Format::HtmlEncoded for user-generated content, then render with Blade's unescaped output syntax only when appropriate. Confirm the exact escaping behavior during your proof of concept.
- How do I extract URLs from a string instead of making them clickable?
- Use the Highlighter find() method, which replaces the older getUrls() method in version 4. It returns the matched URLs so you can store, count, validate, or process them without generating HTML. This is useful for link inventories, analytics, log processing, and notification workflows.
- How do I highlight URLs inside HTML content without creating nested anchor tags?
- Version 4 adds HTML-aware highlighting and skips content inside elements where links should not be inserted, including a, button, script, style, textarea, title, select, svg, and similar containers. That removes the most common need to strip tags before highlighting stored rich text. Still test against your actual CMS or forum HTML because malformed markup and custom tags can affect results.
- What happened to isUrl() and the Laravel validator in url-highlight v4?
- Version 4 removes isUrl() and the package validator, so the package is no longer a URL validity gatekeeper. Use Laravel's Url validation rule or filter_var($value, FILTER_VALIDATE_URL) instead, and add tests for the cases your old validator covered. This is a behavioral change for teams that relied on the package to validate user input.
- Can I customize link markup with target=_blank, rel=noopener, or CSS classes?
- Version 4 replaces encoder injection with the Format enum, and the enum is closed, so custom markup is not directly guaranteed by the documented API. Verify target, rel, CSS class, and Markdown output requirements during your proof of concept. If those needs are not met, wrap the package in an internal adapter or post-process output to avoid a functional regression from v3 callbacks.
- How should I handle HTML-encoded user input when highlighting URLs?
- Choose Format based on the delivery surface: Plain for email, logs, and CLI; Html for trusted CMS rendering; and HtmlEncoded for user-generated content that is already entity-encoded. This maps cleanly to common Laravel rendering paths, but you should confirm exact escaping semantics during the proof of concept. Do not assume Html is safe for untrusted input.
- Does url-highlight detect URLs without a scheme or IP address hosts?
- Yes, the library matches URLs without a scheme by top-level domain. Version 4 also adds IP host support, but IP hosts are matched only when they include a port or path. That improves coverage for internal tools, admin consoles, and log views while limiting false positives.
- Is vstelmakh/url-highlight suitable for production Laravel apps, and how should I test it?
- It is suitable for URL extraction and highlighting in CMS content, forums, email processing, logs, and analytics tooling, provided your runtime meets PHP 8.4. Test complex URLs, encoded input, URLs without schemes, IP hosts with ports or paths, and HTML containing existing anchors and skipped elements. Also test your Blade directive, container binding, and any custom output adapter before relying on it in production.