1
2<?php
3$string = 'The quick brown fox jumps over the lazy dog.';
4$patterns = array();
5$patterns[0] = '/quick/';
6$patterns[1] = '/brown/';
7$patterns[2] = '/fox/';
8$replacements = array();
9$replacements[2] = 'bear';
10$replacements[1] = 'black';
11$replacements[0] = 'slow';
12echo preg_replace($patterns, $replacements, $string);
13?>
14
15
1
2<?php
3$string = 'April 15, 2003';
4$pattern = '/(\w+) (\d+), (\d+)/i';
5$replacement = '${1}1,$3';
6echo preg_replace($pattern, $replacement, $string);
7