用regex改进URL解释

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用regex改进URL解释相关的知识,希望对你有一定的参考价值。

A source to help you interpreting URLs in plain text as a html link. It's an improvement of what was proposed here : http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/
  1. // Returns the text given as parameter, with contained URLs interpreted as HTML links
  2.  
  3. function link($text){
  4. return preg_replace('@((https?://)?([-w]+.[-w.]+)+w(:d+)?(/([-w/_.]*(?S+)?)?)*)@', '<a href="$1">$1</a>', $text);
  5. }

以上是关于用regex改进URL解释的主要内容,如果未能解决你的问题,请参考以下文章