In example below, we're going to find and replace only a certain string by defining its pattern.


Example


$string = 'Hello today is 2010-12-31T23:13:43+0001 and fun time ...';

$ISO8601pattern = '/\b(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\+(\d{4})\b/';

echo preg_replace($ISO8601pattern, 'MY FAVORITE DAY', $string);

Result


Hello today is MY FAVORITE DAY and fun time ...