Download the PHP package vstelmakh/url-highlight without Composer

On this page you can find all versions of the php package vstelmakh/url-highlight. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package url-highlight


Checks Packagist Downloads

URL Highlight – PHP library to find URLs in text and turn them into clickable links. Made to handle complex URLs, HTML markup and edge cases.

🚀 See examples 👀

Installation

Requires PHP 8.4+ with the mbstring extension.

Install the latest version with Composer:

On PHP below 8.4, use version ^3.2. It supports PHP 7.1 – 8.x but has a different API, see the 3.x readme.
Coming from 3.x? See Upgrade 3.x to 4.0.

Usage

UrlHighlight is the only entry point. It provides 2 methods:

Highlight URLs

Pass your input text to highlight() and get it back with every URL replaced by a link. Everything else stays as it is.

Two optional arguments control the result: $highlighter renders each URL, $format tells the library how to read the input text.

Custom Highlighter

By default, each URL is simply wrapped in an anchor tag by SimpleHighlighter. For any custom logic, you can use a CallbackHighlighter. The example below adds a nofollow attribute and uses the host as the link text:

A highlighter does not have to produce a link. The returned string replaces the URL, so it may be anything, for example [redacted] for URLs pointing to an external host.

[!TIP] There is also the Highlighter interface. Implement it in a dedicated class for more complex logic. Such a highlighter is reusable and testable. See SimpleHighlighter for an example.

[!IMPORTANT] The returned string from highlighter is written to the output as is. Remember to escape HTML when necessary.

Input Format

The $format argument must describe the input text, otherwise URLs may not be highlighted correctly.

Format Text
Format::Html (default) HTML markup. Tags and elements that may not hold a link are left untouched.
Format::HtmlEncoded HTML markup with entity encoded text, e.g. the result of htmlspecialchars.
Format::Plain Text without markup, taken as is. Angle brackets are ordinary characters.

The default Format::Html fits text without markup as well. Use Format::Plain when angle brackets in the text must stay ordinary characters, for example to match <[email protected]>.

A common case is user input that you escape before rendering. Set the format to Format::HtmlEncoded, so the escaped text is processed correctly:

[!NOTE] Format::HtmlEncoded matches against the decoded text, so the URL ends where it really ends, instead of running into the markup that follows. It does more work internally than the other formats, so use it only for encoded text.

Find URLs

Pass your input text to find() and get the list of URLs it contains, each as a Url object with the components parsed. Markup is ignored, the text is always processed as plain text.

[!TIP] See Url for all available components and methods.

Contributing

Contributions are welcome. Please check out CONTRIBUTING.md for guidelines.
If you find this library useful, don't hesitate to give it a star! ⭐

Credits

Volodymyr Stelmakh
Licensed under the MIT License. See LICENSE for more information.


All versions of url-highlight with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package vstelmakh/url-highlight contains the following files

Loading the files please wait ...