Converting links into clickable hyperlinks
The following function is used to change an email address or URL into a clickable HTML hyperlink using eregi_replace.
Example<?php
<?phpfunction convertLinktoClickableLinks($text) {
$text = eregi_replace(’(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)’,
‘<a href=”\\1″ mce_href=”\\1″>\\1</a>’, $text);
$text = eregi_replace(’([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)’,
‘\\1<a href=”http://\\2″ mce_href=”http://\\2″>\\2</a>’, $text);
return $text;
}
// Email address example
$input = “email@domainname.com”;
echo convertLinktoClickableLinks($input);
echo “<br /><br />”;
// URL example
$input = “http://www.samplesite.com”;
echo convertLinktoClickableLinks($input);
?>
In above example, Email address, Site URL has been passed to convertLinktoClickableLinks function as input. Inside function using eregi_replace the link has been converted to link.
