You can use the PHP str_replace() function to replace all the occurrences of a word within a string.
In the following example the word "facts" is replaced by the word "truth".
<?php
$my_str = 'If the facts do not fit the theory, change the facts.';
// Display replaced string
echo str_replace("facts", "truth", $my_str);
?>
The PHP str_replace() function is case-sensitive, however if you want to perform case-insensitive match and replace you can use the str_ireplace() function.
Use the PHP
str_replace()functionYou can use the PHP
str_replace()function to replace all the occurrences of a word within a string.In the following example the word "facts" is replaced by the word "truth".
The PHP str_replace() function is case-sensitive, however if you want to perform case-insensitive match and replace you can use the str_ireplace() function.
need an explanation for this answer? contact us directly to get an explanation for this answer