fork(2) download
  1. <?php
  2. $content = "I am an image (http://e...content-available-to-author-only...e.com/image.png) and here's another one: https://www.google.com/image1.gif. I want to be transformed to a proper link: http://www.google.com";
  3.  
  4. $regex_images = '~https?://\S+?(?:png|gif|jpe?g)~';
  5. $regex_links = '~(?<!src=\')https?://\S+\b~';
  6.  
  7. $content = preg_replace($regex_images, "<img src='\\0'>", $content);
  8. $content = preg_replace($regex_links, "<a href='\\0'>\\0</a>", $content);
  9. echo $content;
  10.  
  11. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
I am an image (<img src='http://e...content-available-to-author-only...e.com/image.png'>) and here's another one: <img src='https://www.google.com/image1.gif'>. I want to be transformed to a proper link: <a href='http://www.google.com'>http://www.google.com</a>