$string = "123-[toB][toB][toB]-567-[toB]-78-[toB][toB]";
// should echo 123-b-567-b-78-b
How can I replace the [toB] into a letter b even it is repeated?
str_replace('[toB]','b', $string);
gives me 123-bbb-567-b-78-bb
but need // 123-b-567-b-78-b
Replace several instances to a char in string
Moderator: General Moderators
Re: Replace several instances to a char in string
something like..
preg_replace('/[toB]{2,}/','b',$string);
preg_replace('/[toB]{2,}/','b',$string);