Re: String replace

From: Date: Fri, 11 Apr 2003 11:54:46 +0000
Subject: Re: String replace
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-143483@lists.php.net to get a copy of this message
No, str_replace should be used in this case. No point in using regex if you don't need it, and it will reduce performance. Pavel Jartsev wrote:
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. :)
-- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.

« previous php.general (#143483) next »