string replace php regex code example
Example 1: php preg replace
preg_replace($pattern, $replacement, $subject [, $limit [, &$count]]);
Example 2: php preg_replace function
preg_replace($pattern, $replacement, $string);
Example 3: php string replace regex
<?php
$string = 'The quick brown fox jumps over the lazy dog.';
$patterns = array();
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements = array();
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $string);
?>