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

    look up the function eregi_replace() and all of the string functions in the manual.

    this is the type of thing you don't have to do yourself, it is built into php.

      thanks, but I don't know how regular expressions work, do you know a place where it is explained well?

        never mind .. :o)
        I managed to do it with explode();
        I am minding regular expressions for a while.. :o)

          Write a Reply...