如何自动将URL转换为PHP中的超链接? [英] How do I auto convert an url into a hyper link in PHP?

查看:139
本文介绍了如何自动将URL转换为PHP中的超链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输出状态更新的脚本,我需要编写一个脚本,自动将 www.example.com 等内容更改为大块文本中的超链接像Twitter和Facebook一样。我可以在PHP中使用哪些函数?如果你知道一个教程,请张贴它。

I have a script that outputs status updates and I need to write a script that automatically changes something like www.example.com into a hyper link in a chunk of text like Twitter and Facebook do. What functions can I use for this in PHP? If you know a tutorial please post it.

推荐答案

$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

这篇关于如何自动将URL转换为PHP中的超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆