Escape the [] with \.
echo preg_replace("/$pattern/","[find]");

Andrey Hristov
IcyGEN Corporation
On Friday 05 October 2001 21:17, you wrote:
> Hello!
> I just want to replace a string with another, but I have problems, when the
> string contains a [ or something similar. I just need a method to replace
> "[cool]" with "text". When I use:
> $mustbereplaced = "[cool]";
> $message = preg_replace("/$mustbereplaced/", "hello", $message);
> only cool will be replaced with hello, but the [ and ] is still there.
> When I use $message = preg_replace("/$mustbereplaced/e", "hello",
> $message); nothing happens.
> What must I change, that EVERY string will be replaced?
> Hope someone can help me,
> W. Kiecksee


PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to