PHP search a string for http:// or www [duplicate]
Possible Duplicate:
Detecting a url using preg_match? without in the string
I wanting to search a string that is input by the user, for instances of http:// if one is found I want to wrap the link in the correct html,
so for example, the following could be input by a user,
Google's url is http://www.google.com,
what I want to save that as it,
Google's url is <a href="http://www.google.com/">http://www.google.com</a>
is this pos开发者_开发百科sible?
function make_clickable($sText) {
$sClickText = str_replace(' www.', ' http://www.', $sText);
$sClickText = preg_replace("/([\s])?(http|ftp|https)([\:\/\/])([^\s]+)/i", " <a href=\"$2$3$4\" target=\"_blank\">$2$3$4</a>",$sClickText);
return $sClickText;
}
Tadaa!
精彩评论