fork download
  1. <?php
  2.  
  3. $re = '@\b(([\w-]+://?|www[.])[^\s()<>]+(?:\(\w+\)|([^[:punct:]\s]|/)))@i';
  4. $str = "www.domain.com\nhttp://w...content-available-to-author-only...n.com\nhttp://d...content-available-to-author-only...n.com";
  5. $subst = '<a href="$0" target="_blank">$0</a> ';
  6. $result = preg_replace($re, $subst, $str);
  7. echo $result;
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
<a href="www.domain.com" target="_blank">www.domain.com</a> 
<a href="http://w...content-available-to-author-only...n.com" target="_blank">http://w...content-available-to-author-only...n.com</a> 
<a href="http://d...content-available-to-author-only...n.com" target="_blank">http://d...content-available-to-author-only...n.com</a>