There are many ways to do this:
This is a snippet from one of my earlier (unused) apps:
$stuff = "Hello [name] Where how are you? Good [NaMe]!";
$stuff = preg_replace("/\[name\]/i","big.nerd",$stuff);
This is a very basic implementation that is not without its issues, but is a good start, as it is not case sensitive.
I would look into the preg_replace(), preg_match() and read up on some Regular Expression tutorials to help you get started.