fork download
  1. <?php
  2.  
  3. $string = "There is an URL in the middle of nowhere: **http://w...content-available-to-author-only...e.com/dnvjndjnvjd** and here's another one **http://w...content-available-to-author-only...e.com/ddadadada**";
  4.  
  5. $regex = '~\*{2}(https?://(?:www\.)?(\S+))\*{2}~';
  6.  
  7. $string = preg_replace_callback($regex,
  8. function($match) {
  9. return "<a href='{$match[1]}'>" . substr($match[2], 0, 10) . "</a>";
  10. },
  11. $string);
  12.  
  13. echo $string;
  14. ?>
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
There is an URL in the middle of nowhere: <a href='http://w...content-available-to-author-only...e.com/dnvjndjnvjd'>example.co</a> and here's another one <a href='http://w...content-available-to-author-only...e.com/ddadadada'>example.co</a>