fork download
  1. <?php
  2.  
  3. $input = "<img src=\"http://w...content-available-to-author-only...e.com/img/img.png\" alt=\"A Title\">";
  4.  
  5. $filtered_string = preg_replace_callback(
  6. '~(<img.+src=".*\/).*(\.[^"]*)(".+alt="([^"]+).*)~',
  7. function($m) {
  8. return $m[1] . str_replace(" ","_",strtolower($m[4])) . $m[2] . $m[3];
  9. },
  10. $input
  11. );
  12.  
  13. echo $filtered_string;
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
<img src="http://w...content-available-to-author-only...e.com/img/a_title.png" alt="A Title">