str_replace()
Perform a global search and replace within a string. This function can take multiple search and replace pairs and will go through them one at a time.
The parameter order here is:
search, replace, original string, count
This search is case-sensitive. The fourth parameter is optional. The variable placed there will be given the value of the number of replacements made.
Your search and replace parameters must both be either strings or arrays, or search can be an array and replace be a string.
If your search parameter is an array, it will be gone through one at a time. If your replace parameter is then a string, that value will be used to replace each of the search values.
If the replacement is also an array, however, they will be paired up with the search array elements. Should your replace array contain fewer elements than the search array, an empty string will be used for the “missing” elements.
$str = 'Your wish is my command.'; $new = str_replace( 'Your', 'His', $str ); // His wish is my command. $new = str_replace( 'your', 'His', $str ); // Your wish is my command. $new = str_replace( array( 'wish', 'command' ), array( 'whim', 'desire' ), $str ); // Your whim is my desire. $new = str_replace( array( 'wish', 'command' ), array( 'whim' ), $str ); // Your whim is my . $new = str_replace( array( 'wish', 'command' ), 'casa', $str ); // Your casa is my casa. $new = str_replace( 'i', 'QQ', $str, $count ); // Your wQQsh QQs my command. // $count will have the value 2
