PHP str_replace

前端 未结 7 2016
渐次进展
渐次进展 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:42

    Yet one more solution (more for a dynamic number of Xs):

    I also added the \b in to the pattern to only replace Xs that are free-standing, so "FAUX PAS X" only replaces the last X.

    demo

    alphabet_replace (more modular form)

提交回复
热议问题