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
Without use of regex
$arr = explode('X', 'X X X X'); $rep = array('A','B','C','D'); foreach ($arr as $idx=>$val) { $arr[$idx] = $val.$rep[$idx]; } echo implode($arr);