Tags
Asked 2 years ago
9 Jun 2021
Views 218
jignesh

jignesh posted

why str_replace replacing itself in php?

why str_replace replacing itself in php?
jagdish

jagdish
answered Apr 25 '23 00:00

If s tr_replace is replacing itself in PHP, it may be due to the fact that the search string and the replacement string are the same.

For example, if you have the following code:



$text = 'hello world';
$new_text = str_replace('world', 'world', $text);

The $new_text variable will still contain the original text, "hello world". This is because the search string "world" and the replacement string "world" are the same, so no actual replacement takes place.

To avoid this issue, make sure that the search and replacement strings are different.
Post Answer