PHP Function Substr_Replace()
The php function substr_replace() is used to replace text within a string. The function accepts the original string, the replacement string and the starting position as parameters. It also has an optional length parameter which defines the number of characters from the end of the string that need to be replaced. The function returns the string that has been replaced, or if an array of strings was passed, it will return the array.
The first parameter, $string is the original string that needs to be replaced. The second parameter, $replacement is the replacement string that will be inserted into the original string. The third parameter, $start is the index in the string from which the replacement starts. The last parameter, $length is an optional value that specifies the number of characters from the end of the original string that need to be replaced. If this value is not given, then insertion will take place instead of replacing.
Tip: This function can be used to replace multiple strings at a time by passing an array of strings as the input. In such cases the array elements will be replaced in turn as per the values provided in the start, length and replacement parameters.
If you are interested in becoming a full-stack web developer, learn about php and other in demand programming languages with Simplilearn’s Full-Stack Web Development Certification course. Get started today!