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_callback():
// as many as you think you'll need, maximum.
// this can be programmatically generated, if need be
$replacements = array('A', 'B', 'C', 'D', 'E', 'F', 'G'); // and so on
function get_replace_value($matches) {
global $replacements;
return array_shift($replacements);
}
$var = preg_replace_callback("/" + preg_quote($needle) + "/",
"get_replace_value", $var);