How do I replace certain parts of my string?

php, replace, string

Solution

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

Or to answer your question more precisely:

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

Problem

How can I replace a certain part of my string with another one? Input string: ``` "Hello, my name is Santa" ``` 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.

Original source

Related problems