PHP 正则表达式函数库(两套)(2)


$string = "April 15, 2003";
$pattern = "/(\w+) (\d+), (\d+)/i";
$replacement = "\${1}1,\$3";
print preg_replace($pattern, $replacement, $string);


preg_match_all()进行全局正则表达式匹配
语法格式:

复制代码 代码如下:


preg_match_all ("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_PATTERN_ORDER);
print $out[0][0].", ".$out[0][1]."
";
print $out[1][0].", ".$out[1][1]."
";


输出结果:<b>example: </b>, <div align=left>this is a test</div> example: , this is a test

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wfwyzj.html