fork(1) download
  1. <?php
  2.  
  3. $str = 'Hi my name is Harry you can find my website here: http://w...content-available-to-author-only...x.com. Oh and what do you think of my my wife: http://w...content-available-to-author-only...e.com/wife.jpg?';
  4. $r1 = '/(http:\/\/[\S]+(?:jpg|jpeg|png|gif))/';
  5. $r2 = '/(?<!src=")(http:\/\/[\S]+\b)/';
  6. $sub1 = '<img src="$1"/>';
  7. $sub2 = '<a href="$1">$1</a>';
  8. $res = preg_replace($r1, $sub1, $str);
  9. $result = preg_replace($r2, $sub2, $res);
  10. echo $result;
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
Hi my name is Harry you can find my website here: <a href="http://w...content-available-to-author-only...x.com">http://w...content-available-to-author-only...x.com</a>. Oh and what do you think of my my wife: <img src="http://w...content-available-to-author-only...e.com/wife.jpg"/>?