php 正则表达式 替换字符串URL链接为a标签超链接

<?php

$regex = '@(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))@';

$content = 'http://route.cn/Home/UserCenter 哈哈哈';
$content = preg_replace($regex, '<a href="$1">网页链接</a>', $content);

echo $content;

如果能帮到你我很高兴

猜你喜欢

转载自blog.csdn.net/weixin_44296452/article/details/113351691