$string = “April 15, 2003”;
$pattern = “/(\w+) (\d+), (\d+), (\d+ 43;)/i”;
$replacement = “\${1}1,\$3”;
print preg_replace($pattern, $replacement, $string );
preg_match_all() for global regular expression matching
Grammar format :
preg_match_all (“|]+>(. *)[^>]+>|U”,
“example:
this is a test”,
$out, PREG_PATTERN_ORDER) ;
print $out[0][0].”, “.$out[0][1].”
“;
print $ out[1][0].”, “.$out[1][1].”
“;
Output result :example: ,
this is a test example: , this is a test
Original :http://www.jb51.net/article/20400.htm