且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何自动将URL转换为PHP中的超链接?

更新时间:2023-02-23 10:41:04

$string = " fasfasd  http://webarto.com   fasfsafa";

echo preg_replace("#http://([\S]+?)#Uis", '<a rel="nofollow" href="http://\\1">\\1</a>', $string);

输出:

 fasfasd  <a rel="nofollow" href="http://webarto.com">webarto.com</a>   fasfsafa