I am having a problem with bit of code.
This is the code
$test ='<number>1<number>2</number>3</number>';
$i=0;
$find[$i]="#<number>(.*)</number>#is";
$replace[$i]="5";
$i++;
$find[$i]="#<number>(.*)</number>#is";
$replace[$i]="$1";
echo htmlentities(preg_replace($find, $replace, $test));
At the moment this displays just the numnber 5 in the results.
But i want it to display 153
Does anyone know what I am doing wrong?
thanks
Yes, since
.*matches everything (including the tags), you’re matching too much. If you restrict your regex not to match across tag boundaries by preventing it from matching angle brackets, you get the desired result: