Re: str_replace on words with an array

From: Date: Sun, 29 Oct 2006 21:54:00 +0000
Subject: Re: str_replace on words with an array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-243841@lists.php.net to get a copy of this message
I never use this function, since I always use regular expressions, but according to the manual: If you don't need fancy replacing rules (like regular
         expressions), you should always use this function instead of
         ereg_replace() or preg_replace().
So, I assume your problem initially was that you were using regular expression syntax and this function doesn't accept regular expressions. Is your aim to get rid strings of all the items in the $noiseArray? Your $noiseArray includes the entire alpahabet, so it's no wonder that you end up with empty strings! Myron Dotan Cohen wrote:
On 29/10/06, Alan Milnes <css@milnes7.com> wrote:
Dotan Cohen wrote:
$searchQuery=str_replace( "^".$noiseArray."$", " ", $searchQuery);
Can you explain what you are trying to do with the ^ and $? What is a typical value of the original $searchQuery? Alan
The purpose of the ^ and the $ is to define the beginning and the end of a word: http://il2.php.net/regex I also tried str_replace( $noiseArray, " ", $searchQuery) but that was replacing the insides of words as well. And with the addition of the individual letters, that emptied the entire $searchQuery string! A typical value of $searchQuery could be "What is php?" or "What is open source". See this site for details: http://what-is-what.com Dotan Cohen http://technology-sleuth.com/
-- _____________________ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/

« previous php.general (#243841) next »