开发者

PHP search a string for http:// or www [duplicate]

This question already has answers here: Closed 11 years ago.

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜