Replace "[n]blah[n]blah[n]" > "1blah2blah3"

I can do this easily with PHP5 but for what im doing i would like to keep it in PHP4 for various reasons.

Basically every [n] is found in order and replaced with number. Whats the easiest way to do this that puts the least amount of stress on the CPU.