Download the PHP package youthweb/urllinker without Composer
On this page you can find all versions of the php package youthweb/urllinker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download youthweb/urllinker
More information about youthweb/urllinker
Files in youthweb/urllinker
Package urllinker
Short Description Autolink URLs in text or html
License GPL-3.0-or-later
Homepage https://github.com/youthweb
Informations about the package urllinker
UrlLinker
UrlLinker converts any web addresses in plain text into HTML hyperlinks.
This is a maintained fork of the great work of Kwi\UrlLinker, formerly on Bitbucket.
Install
Via Composer
Usage
You can optional configure different options for parsing URLs by passing them to UrlLinker::__construct()
:
Recognized addresses
- Web addresses
- Recognized URL schemes: "http" and "https"
- The
http://
prefix is optional. - Support for additional schemes, e.g. "ftp", can easily be added by
setting
allowFtpAddresses
totrue
. - The scheme must be written in lower case. This requirement can be lifted
by setting
allowUpperCaseUrlSchemes
totrue
. - Hosts may be specified using domain names or IPv4 addresses.
- IPv6 addresses are not supported.
- Port numbers are allowed.
- Internationalized Resource Identifiers (IRIs) are allowed. Note that the job of converting IRIs to URIs is left to the user's browser.
- To reduce false positives, UrlLinker verifies that the top-level domain is on the official IANA list of valid TLDs.
- UrlLinker is updated from time to time as the TLD list is expanded.
- In the future, this approach may collapse under ICANN's ill-advised new policy of selling arbitrary TLDs for large amounts of cash, but for now it is an effective method of rejecting invalid URLs.
- Internationalized top-level domain names must be written in Punycode in order to be recognized.
- If you want to support only some specific TLD you can set them with
validTlds
e.g.['.com' => true, '.net' => true]
. - If you need to support unqualified domain names, such as
localhost
, you can also set them with['.localhost' => true]
invalidTlds
.
- Email addresses
- Supports the full range of commonly used address formats, including "plus addresses" (as popularized by Gmail).
- Does not recognized the more obscure address variants that are allowed by the RFCs but never seen in practice.
- Simplistic spam protection: The at-sign is converted to a HTML entity, foiling naive email address harvesters.
- If you don't want to link emails you can set closure that simply returns the
raw email with a closure
function($email, $content) { return $email; }
inemailLinkCreator
.
- Addresses are recognized correctly in normal sentence contexts. For instance, in "Visit stackoverflow.com.", the final period is not part of the URL.
- User input is properly sanitized to prevent cross-site scripting (XSS),
and ampersands in URLs are correctly escaped as
&
(this does not apply to thelinkUrlsInTrustedHtml()
function, which assumes its input to be valid HTML).
Changelog
Please see CHANGELOG for more information what has changed recently.
Tests
Unit tests are written using PHPUnit.
Contributing
Please feel free to submit bugs or to fork and sending Pull Requests. This project follows Semantic Versioning 2 and PSR-2.
License
GPL3. Please see License File for more information.