Have a Snippet?

Keep, track and share your code snippets with your friends

PHP: Make a clickable text Share on Vkontakte

Make a clickable text: replace all the URLs with tag

function makeClickable($text) {
    $text = preg_replace("/(^|[\n ])([\w]*?)((ht|f)tp(s)?:\/\/[\w]+[^ \,\"\n\r\t<]*)/is", "$1$2$3", $text);
    $text = preg_replace("/(^|[\n ])([\w]*?)((www|ftp)\.[^ \,\"\t\n\r<]*)/is", "$1$2$3", $text);
    $text = preg_replace("/(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+)+)/i", "$1$2@$3", $text);
    return($text);
}


Tag: PHP, Strings, URL

0 Comments