I have the string $var in which I need to replace some text. The first \"X\" needs to be replaced by \"A\", the second \"X\" needs to be replaced by B and so on, here is an exam
You could use preg_replace's limit argument to only replace once.
limit
http://codepad.viper-7.com/ra9ulA