我有一个脚本输出状态更新,我需要编写一个脚本,自动更改www.example.com像Twitter和Facebook这样的大块文本中的超链接.我可以在PHP中使用哪些函数?如果你知道一个教程,请发布它.
$string = " fasfasd http://webarto.com fasfsafa";
echo preg_replace("#http://([\S]+?)#Uis", '<a rel="nofollow" href="http://\\1">\\1</a>', $string);
Run Code Online (Sandbox Code Playgroud)
输出:
fasfasd <a rel="nofollow" href="http://webarto.com">webarto.com</a> fasfsafa
Run Code Online (Sandbox Code Playgroud)