将文本转换为超链接 [英] Converting text to hyperlink

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

问题描述

在任何网站的文本编辑器中输入'codeproject.com'时,如何将其转换为'对于那些代码'作为超链接并通过网络重定向到codeproject.com。

While typing 'codeproject.com' in a text editor of any website, how can you convert it into 'For those who code' as hyperlink and redirecting to codeproject.com through out the web.

推荐答案

您好,



您可以尝试在PHP中使用正则表达式( http://php.net/manual/en/function.preg-match.php [ ^ ])以获得该结果。请关注 [ ^ ]教程。



你需要做的就是用这个来检测网址

Hi,

You may try to use regex in PHP (http://php.net/manual/en/function.preg-match.php[^]) in order to get that result. Follow this[^] tutorial.

What you have to do is simply detect the URL with this
#(?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`!()\[\]{};:'".,<>?«»""‘’]))#iS 


$ b例如,$ b regex。您可以在这里找到其他正则表达式[ ^ ]。然后只需按照上述教程中解释的查找并替换字符串来转换HTML表达式的URL。


如果你有关于它的其他线索,请随意发表评论;)



希望这会有所帮助。



LG


regex for instance. You can find other regexes here[^]. And then simply follow the point Finding and replacing strings explained on the aforementioned tutorial to convert the URL to an HTML expression.

Feel free to comment if you have other clues about it ;)

Hope this helps.

LG


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

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