The preg_replace() function is an in-built function that returns a word or array of words with the replacement of some content after searching the pattern. If the search pattern is not found then it will be returned unchanged.
- Declare a variable with a string value.
- Use preg_replace() function to replace the first character of every word.
- Display the replaced value of the string variable.