How to replace a content using regular expression search in php?

It’s as follows :-

 <?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}1,$3';
echo preg_replace($pattern, $replacement, $string);
?> 
O/p :-
April1,2003

Leave a Reply