The following example uses the str_replace() function to replace the string 'Hello' with 'Hi' in the string 'Hello there': ' // Hi there echo $str. Simple PHP str_replace() function examples Let’s take some examples of using the PHP str_replace() function. It returns a new array with the $search replaced with the $replace. Note that the str_replace() doesn’t change the input string ( $subject). If the $search is an array and the $replace is a string, then the str_replace() function replaces every element in the $search with the $replace string. If the $replace array has fewer elements than the $search array, the str_replace() function uses an empty string for the replacement values. If the $search and $replace arguments are arrays, the str_replace() takes each value from the $search array (from left to right) and replaces it with each value from the $replace array. The $count returns the number of replacements that the function performed.The $replace is the replacement string that replaces the $search value.The $search is a substring to be replaced.The str_replace() has the following parameters: ) : string| array Code language: PHP ( php ) The following shows the syntax of the str_replace() function: str_replace ( The PHP str_replace() function returns a new string with all occurrences of a substring replaced with another string. Summary: in this tutorial, you’ll learn how to use the PHP str_replace() function to replace all occurrences of a substring with a new string Introduction to the PHP str_replace() function
0 Comments
Leave a Reply. |