preg_replace_callback: <?php$str='this is a test for this string includes many this';$replace='/this/x';$result=preg_replace_callback( $replace, function($ms){ static $i; $i=$i+1; return "that($i)"; }, $str );echo $result,"\n";
[code] <?php $str='this is a test for this string includes many this';$replace='/this/e';function userdefine() { static $i; $i=$i+1; return "that($i)"; } $result=preg_replace( $replace, "userdefine()", $str );echo $result,"\n";?> [/code]
<?php $str='this is a test for this string includes many this';$replace='/this/e';function userdefine() { static $i; $i=$i+1; return "that($i)"; } $result=preg_replace( $replace, "userdefine()", $str );echo $result,"\n";?>
如$neirong中有包含3个$skx 把第一个替换成1 第二个替换成2 第三个替换成3 就像if加循环ID一样
<?php$str='this is a test for this string includes many this';$replace='/this/x';$result=preg_replace_callback(
$replace,
function($ms){
static $i;
$i=$i+1;
return "that($i)";
},
$str
);echo $result,"\n";
<?php
$str='this is a test for this string includes many this';$replace='/this/e';function userdefine()
{
static $i;
$i=$i+1;
return "that($i)";
}
$result=preg_replace(
$replace,
"userdefine()",
$str
);echo $result,"\n";?>
[/code]
$str='this is a test for this string includes many this';$replace='/this/e';function userdefine()
{
static $i;
$i=$i+1;
return "that($i)";
}
$result=preg_replace(
$replace,
"userdefine()",
$str
);echo $result,"\n";?>
preg_replace_callback(PHP 4 >= 4.0.5)
preg_replace_callback -- 用回调函数执行正则表达式的搜索和替换