9.3.8 字符串中正则的其它函数
test.php
<?php
$text = "今天是2014-02-14, 明年的2015-02-14你和谁会在一起呢?";
echo $text."<br>";
$reg = "/(\d{4})(-\d{2}-\d{2})/";
function myfun($m) {
return ($m[1]+1).$m[2];
}
echo preg_replace_callback($reg, "myfun", $text);
demo.php
<?php
$text = "this *is* a test";
$reg = "/".preg_quote("*is*")."/"; // /\*is\*/
echo preg_replace($reg, "##", $text);