What i find myself?
Find links in text and replace to href with PHP
Here is the code to find the link in text and replace link as href,
function addlinks($text = ""){
// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {
// make the urls hyper links
returnĀ preg_replace($reg_exUrl, "<a href='{$url[0]}'>{$url[0]}</a> ", $text);
} else {
// if no urls in the text just return the text
return $text;
}
}
Example
Text : This is google website http://google.com
Output : This is google website http://google.com
Please comment with jQuery or javascript method to do the same.
Thanks in advance
Amjith
| Print article | This entry was posted by CoolCoder on April 16, 2011 at 3:26 pm, and is filed under Misc, PHP. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |