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
1$result = preg_replace('/abc(def)hij/', '/\\1/', $string);
2$result = preg_replace('/abc(def)hij/', '/$1/', $string);
3$result = preg_replace('/abc(def)hij/', '/${1}/', $string);
4
1$result = preg_replace(
2 array('/pattern1/', '/pattern2/'),
3 array('replace1', 'replace2'),
4 $string
5);
6
1$text = preg_replace_callback(
2
3"/\\[\\[([^|]+\\|)(.*?)\\]\\]/",
4
5[ $this, 'linkReplace' ],
6
7$text
8
9);
10
11$text = preg_replace( "/<\/?[^>]+>/", "", $text );
12return $text;
1# Strip HTML tag
2$result = preg_replace('#<span id="15">.*</span>#m', '', $string);
3