这次给大家带来怎样确认文本里url或邮件地址是否为真,确认文本里url或邮件地址为真的注意事项有哪些,下面就是实战案例,一起来看一下。
这段代码可以分析出文本里的所有超级链接,包含邮件、url、#链接等等,并分别输出为真实链接地址
$.fn.tweetify = function() { this.each(function() { $(this).html( $(this).html() .replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>') .replace(/(^|\s)#(\w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>') .replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>') ); }); return $(this); }
用法:
$("p").tweetify();
原始文本:
<p>@seanhood have you seen this http://icanhascheezburger.com/ #lol</p>
分析以后:
<p><a href="http://twitter.com/seanhood">@seanhood</a> have you seen this <a href="http://icanhascheezburger.com/">http://icanhascheezburger.com/</a> <a href="http://search.twitter.com/search?q=%23lol">#lol</a></p>
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of How to confirm whether the URL or email address in the text is genuine. For more information, please follow other related articles on the PHP Chinese website!