0 Replies - 318 Views - Last Post: 21 May 2007 - 04:41 AM

#1 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,443
  • Joined: 26-March 01

Convert links into clickable hyperlinks

Posted 21 May 2007 - 04:41 AM

Description: A function to change an email address or URL into a clickable HTML hyperlink using eregi_replace.
<?php

function makeClickableLinks($text) {

  $text = eregi_replace('(((f|ht){1}tp://)[[email protected]:%_+.~#?&//=]+)',
    '<a href="\1">\1</a>', $text);
  $text = eregi_replace('([[:space:]()[{}])(www.[[email protected]:%_+.~#?&//=]+)',
    '\1<a href="http://\2">\2</a>', $text);
  $text = eregi_replace('([_.0-9a-z-][email protected]([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',
    '<a href="mailto:\1">\1</a>', $text);
  
return $text;

}

// Usage

// Email address example
$text = "[email protected]";
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);

?>


Is This A Good Question/Topic? 0
  • +

Page 1 of 1