Re: [PHP] str_replace on words with an array



Dotan Cohen wrote:
Er, so how would it be done? I've been trying for two days now with no
success.

Ok, I guess my original reply didn't get through, or you ignored it.
Here it is again for your convenience.

Dotan Cohen wrote:
$searchQuery=str_replace( "^".$noiseArray."$", " ", $searchQuery);

Ok, this is what the compiler will see...

$searchQuery=str_replace("^Array$", " ", $searchQuery);

Yes, that's a literal Array in the string. You cannot, and you should
remember this, you cannot concatenate strings and arrays. What would you
expect it to do?

Now, the answer is this...

$searchQuery = str_replace($noiseArray, ' ', $searchQuery);

However, what you seem to be doing is putting regex syntax where it
would have no effect even if $noiseArray was not an array. If your
intention is to replace the words rather than just the strings then you
need to look at preg_replace (http://php.net/preg_replace) and you'll
need to decorate the strings in $noiseArray with the appropriate
characters to make them the search pattern you need - full details on
the preg_replace manual page.

-Stut (painfully sober now :( )
.



Relevant Pages

  • Re: K&R2 Secition 5.9 - major blunders
    ... Each element of b doesn't point to a 20 element array of int. ... This mistake is crucial because ... my explanation is really the qualities of something else: ... > The use of the array of pointers is to store the strings. ...
    (comp.lang.c)
  • Re: K&R2 Secition 5.9 - major blunders
    ... Each element of b doesn't point to a 20 element array of int. ... This mistake is crucial because ... my explanation is really the qualities of something else: ... > The use of the array of pointers is to store the strings. ...
    (comp.lang.c)
  • Re: Returning array of strings through callback from unmanaged to
    ... Is the array of strings a jagged array or fixed length array? ... It is imperative that I am able to return the array of strings from the ... I have control over how many strings I want the unmanaged code to return ... What I want to accomplish is to pass a callback function to unmanaged ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: attempting to return values from array from w/in a function
    ... What I get is an array w/ only the most recent array entry. ... I am new to PHP & do not have formal scripting ... you end up comparing strings, but the test you mean probably is simply: ... case 1: {codeblock} ...
    (comp.lang.php)
  • Re: sorting and shuffling array
    ... > I need some help with sorting and shuffling array of strings. ... qsort() library function. ...
    (comp.lang.c)