$start_time = '1030'; $pattern = '/(?<=\d\d)30/'; $start_time = preg_replace($pattern, '50', $start_time); //result: 1050