How to use a local variable in preg_replace_callback
in PHP.
I have the following code:
function pregRep($matches)
{
global $i; $i++;
if($i > 2)
{
return '#'.$matches[0];
}
else
{
return $matches[0];
}
}
$i = 0;
$str = preg_replace_callback($reg_exp,"pregRep",$str);
And also $str
is a string, $reg_exp
is a regex expression. Both of these are well defined.
Thanks for your help.