Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with @verdesmarald and used this pattern in the following function:</p> <pre><code>$string = preg_replace_callback( "_(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)(?:\.(?:[a-z\x{00a1}-\x{ffff}0-9]+-?)*[a-z\x{00a1}-\x{ffff}0-9]+)*(?:\.(?:[a-z\x{00a1}-\x{ffff}]{2,})))(?::\d{2,5})?(?:/[^\s]*)?_iuS", create_function('$match',' $m = trim(strtolower($match[0])); $m = str_replace("http://", "", $m); $m = str_replace("https://", "", $m); $m = str_replace("ftp://", "", $m); $m = str_replace("www.", "", $m); if (strlen($m) &gt; 25) { $m = substr($m, 0, 25) . "..."; } return "&lt;a href=\"$match[0]\"&gt;$m&lt;/a&gt;"; '), $string); return $string; </code></pre> <p>It seem to do the trick, and resolve an issue I was having. As @verdesmarald said, removing the ^ and $ characters allowed the pattern to work even in my pre_replace_callback().</p> <p>Only thing that concerns me, is how efficient is the pattern. If used in a busy/high traffic web app, could it cause a bottle neck?</p> <p><strong>UPDATE</strong></p> <p>The above regex pattern breaks if there is a trail dot at the end of the path section of a url, like so <code>http://www.mydomain.com/page.</code>. To solve this I modified the final part of the regex pattern by adding <code>^.</code> making the final part look like so <code>[^\s^.]</code>. As I read it, do not match a trailing space or dot.</p> <p>In my tests so far it seems to be working fine.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload