I am trying to replace al the instances $idcount in $string, but when replacing $idcount, each time it should increase, how is the best way to do it because the code below isn't working
echo id_replace('this is $idcount, and this is $idcount one more would be $idcount');
// this should output this is 1, and this is 2 one more would be 3
function id_replace ($string) {
while($i<strlen($string)-8) {
if (substr($string,$i,8)=='$idcount') {
$idcount++;
$string.=substr_replace($string,$idcount,$i,8);
$i=$i+7-strlen($idcount);
}
$i++;
/else {
$newstring.=substr($string,$i,1);
}/
}
return $string;
}
Many Thanks,
Bruno