You need to replace a certain word in a string in your PHP script. How would you do this?

  • str_replace($search, $replacement, $string)
  • replace($search, $replacement, $string)
  • substr_replace($search, $replacement, $string)
  • swap($search, $replacement, $string)
To replace a certain word in a string in PHP, you can use the str_replace() function. The str_replace() function performs a search and replace operation on a given string. It replaces all occurrences of the specified search string with the replacement string. Pass the search string, replacement string, and the original string as arguments to the str_replace() function, like this: str_replace($search, $replacement, $string). This will return a new string with the replaced word. Learn more: https://www.php.net/manual/en/function.str-replace.php
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *