As well as searching strings in PHP, often it’s useful to replace text within strings too. For example, it can be handy for manipulating strings containing data, or when formatting text for displaying in a Web page.
PHP gives you a couple of useful functions for replacing text in a string:
str_replace()
searches for one string of text and replaces it with another.substr_replace()
replaces text at a specified position within a string.
Read on to discover how to use these 2 useful PHP functions.