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
str_replace is sufficient for simple replacement jobs (such as replacing a single letter), but the use of preg_replace is generally advised (if you want something more flexible or versatile), because it's flexible and versatile. And as the 'a' is just an example...:
$String = preg_replace('//','',$String);
Or if you want multiple replacements at once:
$String = preg_replace(array('//','//'),array('',''),$String);
preg_replace can, unfortunately, be quite tricky to use. I recommend the following reads: http://php.net/manual/en/function.preg-replace.php http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html
Also, if you decide to use str_replace(), and your replacement needs to be case-sensitive, you're going to need str_ireplace().