Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to parse Hyper-Links and E-mail addresses

Parsing

How to parse Hyper-Links and E-mail addresses

by  BigBadDave  Posted    (Edited  )
Here is a quick function :

function parseHyper($string) {
$search = array ("/([\w\.\/\&\=\?\-]+)@([\w\.\/\&\=\?\-]+)/",
"/((ftp(7?):\/\/)|(ftp\.))([\w\.\/\&\=\?\-]+)/",
"/((http(s?):\/\/)|(www\.))([\w\.\/\&\=\?\-]+)/");
$replace = array ("<a href='mailto:$1@$2'>$1@$2</a>",
"<a href='ftp$3://$4$5' target='_blank'>$4$5</a>",
"<a href='http$3://$4$5' target='_blank'>$4$5</a>");
return preg_replace ($search, $replace, $string);
}

just call it like this :

$string = "www.foo-bar.com";
echo parseHyper($string);

Regards

Big Bad Dave

[img http://www.byngdesigns.co.uk/tek-tips/spider.gif]
www.byngdesigns.co.uk

davidbyng@hotmail.com
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top