Stian Stian - 6 months ago 15
PHP Question

How to replace certain parts of my string?

How can I replace a certain part of my string with another one?

Input string:

Hello my name is Santa"


Now how can I change all
a
's in my string with something else?

I think I need a
foreach
loop, but I'm unsure how to use it.

Answer
strtr ($str, array ('a' => '<replacement>'));

UPDATE:

strtr ("hello my name is santa", array ('a' => '<replacement>'));

To answer your question more precisely.