If you are working with forums, blogs or even a normal form submission, many times you end us asking user for a website. Using the function, the URL string would automatically convert to a hyperlink.
Syntax
1
2
3
4
5
6
7
8
9
10
11
|
function makeClickableLinks($text)
{
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'<a href="\1">\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',
'\1<a href="http://\2">\2</a>', $text);
$text = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',
'<a href="mailto:\1">\1</a>', $text);
return $text;
}
|
1
2
3
4
5
|
<?php
$text = "This is my first post on http://blog.koonk.com";
$text = makeClickableLinks($text);
echo $text;
?>
|
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment