fork download
  1. <?php
  2.  
  3. $re = '~(.*time\s+)(\d{2}:\d{2}\s[ap]m)(.*)~';
  4. $str = "there is some text and maybe some number or symbols time 12:32 am and there is some text";
  5. $new_time = "10:10 pm";
  6. $result = preg_replace($re, '${1}' . $new_time . "$3", $str);
  7. echo $result;
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
there is some text and maybe some number or symbols time 10:10 pm and there is some text