match url pattern in php using regular expression

前端 未结 8 1703
别那么骄傲
别那么骄傲 2020-12-01 18:32

I want to match a url link in wall post and replace this link with anchor tag, for this I use the regular expression below.

I would like the match 4 types of url:

8条回答
  •  一个人的身影
    2020-12-01 18:54

    This works great for me - including mailto check:

    function LinkIt($text)
    {
        $t = preg_replace("/(\b(?:(?:http(s)?|ftp):\/\/|(www\.)))([-a-züöäß0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|])/im", '$1$4', $text);
        return preg_replace("/([\w+\.\-]+@[\w+\-]+\.[a-zA-Z]{2,4})/im", strtolower('$1'), $t);
    }
    

提交回复
热议问题