fork download
  1. <?php
  2. $stringNotSpecial='mySite-1238459846.js'; //Works!
  3. $stringSpecial='stuff BEFORE...<script src=\'/assets/mySite-0123456789.js\'></script>stuff AFTER...';
  4. $timestamp='0123456789';
  5. $pattern = '/mySite-[0-9]+.js/';
  6. echo preg_replace($pattern, 'mySite-'.$timestamp.'.js', $stringNotSpecial);
  7. echo '<br>';
  8. echo preg_replace($pattern, 'mySite-'.$timestamp.'.js', $stringSpecial);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
mySite-0123456789.js<br>stuff BEFORE...<script src='/assets/mySite-0123456789.js'></script>stuff AFTER...