fork download
  1. <?php
  2.  
  3. $str = "<img src=\"http://w...content-available-to-author-only...e.com/img/img.png\" alt=\"A Title\">";
  4.  
  5. $re = '~(<img\s*src=".*\/).*(\.[^"]*)("\s*alt="([^"]+).*)~';
  6.  
  7. preg_match($re, $str, $m);
  8.  
  9. $filtered_string = $m[1] . str_replace(" ","_",strtolower($m[4])) . $m[2] . $m[3];
  10.  
  11. echo $filtered_string;
  12.  
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">