urls2links Php Functions
These are two php functions for converting URLs in a string of text into HTML hyperlinks. Both functions accept URLs with or without protocols, ports, paths, query strings and fragments. They both exclude punctuation marks at the end of the URL, which commonly cause problems in message boards and forums where the punctuation marks are included in the link.
Versions
- urls2LinksSimple
- The simple version. It accepts one parameter - the text with URLs in - and returns the text with the URLs converted to hyperlinks. It accepts the 'http', 'https', 'ftp' and 'ftps' protocols. It does not recognise e-mail addresses.
- urls2linksComplex
- The complex and better version, however it is three times longer than the simple version.
This function finds any URLs complying with RFC3986, with a few exceptions (see the urls2linksComplex documentation page for details), including e-mail addresses. If no scheme (protocol) is given, then it assumes http:// or mailto:, as appropriate.
License
These urls2links php functions are licensed under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License by Martin Pain. This means you are free to use, distribute and modify the functions, as long as you distribute any work you use it in under a similar licence. Click on the image or license name for more information.
