Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

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 ...