PHP Function: Make non linked links clickable

Recently I came across a problem making a twitter plugin. I needed to make links which had no “a” tag into links. You can do this progamaticly and here is the solution:

If you are going to use this script please download from here: links.php.txt

function makeClickableLinks($text) {

$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',

    '1', $text);

  $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',

    '12', $text);

  $text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',

    '1', $text);

return $text;

}

// Usage

// Email address example

$text = "you@example.com";

echo makeClickableLinks($text);

echo "

";

// URL example

$text = "http://www.example.com";

echo makeClickableLinks($text);

echo "

";

// FTP URL example

$text = "ftp://ftp.example.com";

echo makeClickableLinks($text);

34 thoughts on “PHP Function: Make non linked links clickable”

  1. hey there and thank you for your info – I’ve certainly picked up anything new from
    right here. I did however expertise several technical points using this site, since I experienced to reload the web site many
    times previous to I could get it to load properly. I had
    been wondering if your web host is OK? Not that I am complaining, but slow loading instances times will very frequently affect your placement in google and can damage your high-quality score if advertising
    and marketing with Adwords. Anyway I am adding
    this RSS to my e-mail and could look out for a lot more of
    your respective exciting content. Make sure
    you update this again very soon.. Escape rooms

  2. cialis on line He helped introduce premium IOL FOREVER YOUNG lens surgery to cataract surgery to our state His educational background in laser physics as well as medicine makes him uniquely qualified to care for your eyes during your vision correction procedure

Leave a Comment