Hi,
i want to replace one string with another string in php. That replace should consider exact strting.
Ex: this is test
after replacing is with was i want my string to be “this was test”;
plz help me out for this.
Regards Gopi.
[code=php] $map = array( 'is' => 'was', 'foo' => 'bar', 'hello' => 'goodbye' // etc ); $string = 'hello! this is a string containing foo'; $string = str_replace(array_keys($map), $map, $string); echo $string; // outputs "goodbye! this was a string containing bar" [/code]
[code=php] $new = preg_replace('#(?<=^|s)is(?=$|s)#', 'was', $str); [/code]
Help @gpbodapati spread the word by sharing this article on Twitter...