Converting links into clickable hyperlinks

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.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.