PHP str_replace

前端 未结 7 2018
渐次进展
渐次进展 2021-01-25 11:03

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

7条回答
  •  长情又很酷
    2021-01-25 11:39

    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);
    

提交回复
热议问题