php preg replace in preg replcae code example
Example 1: preg_replace
<?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}1,$3';
echo preg_replace($pattern, $replacement, $string);
Example 2: preg_replace examples
$result = preg_replace('/abc/', 'def', $string); # Replace all 'abc' with 'def'
$result = preg_replace('/abc/i', 'def', $string); # Replace with case insensitive matching
$result = preg_replace('/\s+/', '', $string); # Strip all whitespaces