hello, this is my first post I think... it deals with the order of replacement, in the preg_replace() function, when you're replacing multiple values. Kind of hard to explain... but here is an example...
$count = 0;
$text = "in out in out";
$pattern = array('/in/e','/out/e');
$replacement = array('in()','out()');
$return = preg_replace($pattern,$replacement,$text);
function in(){
global $count;
$count++;
echo "IN: ".$count;
return "in: ".1;
}
function out(){
global $count;
$count--;
echo "OUT: ".$count;
return "out: ".0;
}
echo $return;
Ok, I made the code simpler, so you guys can see how it works... now this is the result...
IN: 1
IN: 2
OUT: 1
OUT: 0
in: 1
out: 0
in: 1
out: 0
Notice the $count, how it goes 1-2-1-0... thats because it searches $text for "in" first... than goes back and searches $text for "out"... It doesn't go line by line? Is there anyway (like a modifier) to make PREG searches for everything one time through? Instead of going one $pattern at a time?
My desired result would be:
IN: 1
OUT: 0
IN: 1
OUT: 0
in: 1
out: 0
in: 1
out: 0
Any input would be good. Let me know if you need me to explain more...