preg replace php 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: php preg replace
preg_replace($pattern, $replacement, $subject [, $limit [, &$count]]);
Example 3: preg_replace examples
$result = preg_replace('/abc/', 'def', $string);
$result = preg_replace('/abc/i', 'def', $string);
$result = preg_replace('/\s+/', '', $string);
Example 4: preg_replace examples
$result = preg_replace('/abc(def)hij/', '/\\1/', $string);
$result = preg_replace('/abc(def)hij/', '/$1/', $string);
$result = preg_replace('/abc(def)hij/', '/${1}/', $string);
Example 5: preg_replace examples
$result = preg_replace(
array('/pattern1/', '/pattern2/'),
array('replace1', 'replace2'),
$string
);
Example 6: php preg_replace function
preg_replace($pattern, $replacement, $string);