如何替换字符串的某些部分?
问题描述:
如何用另一部分替换字符串的某个部分?
How can I replace a certain part of my string with another one?
输入字符串:
"Hello, my name is Santa"
如何用其他方式更改字符串中的所有a
?
How can I change all a
's in my string with something else?
我认为我需要一个foreach
循环,但是我不确定如何使用它.
I think I need a foreach
loop, but I'm unsure how to use it.
答
strtr ($str, array ('a' => '<replacement>'));
或者更精确地回答您的问题:
Or to answer your question more precisely:
strtr ("Hello, my name is Santa", array ('a' => '<replacement>'));