Re: String replace
| From: | Pavel Jartsev | Date: | Fri, 11 Apr 2003 11:48:12 +0000 |
| Subject: | Re: String replace | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143481@lists.php.net to get a copy of this message | ||
Uma Shankari T. wrote:
Hello, Can any one please tell me how to replace a matched string in a array with another variable.. suppose..i am having the sentence in the array like this.. $Question= "Queen is a Good girl"; $Quest=explode(" ",$Question); i need to replace the "girl" string with "actor" in the appropriate place..how do i go about with this..U can try 'preg_replace()'-function: $Question = "Queen is a Good girl"; $Quest = explode( " ", preg_replace( '/girl/', 'actor', $Question )); Now, $Quest[4] should be 'actor', not 'girl' anymore. Hope this helps. :) -- Pavel a.k.a. Papi