Re: str_replace on words with an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Paul Novitski wrote:
If you go this route, perhaps you could enclose each member of your original array in \b word boundary sequences using an array_walk routine so that you don't have to muddy your original array declaration statement.

At 10/29/2006 01:54 PM, rich gray wrote:
IIRC str_replace() does not interpret or understand regular expression syntax - you'd need preg_replace() for that


You're absolutely right -- I was focusing so much on the regexp syntax that I failed to broaden my gaze...

When the OP corrects his PHP to use preg_replace() instead of str_replace(), I believe he'll still need to provide word boundaries around each member of his noise-word array, otherwise the function will simply remove all letters and digits from the words in the search-string he considers meaningful and he'll end up searching thin air.

Aside, without knowing the context of his search, it seems a bit extreme to remove all single characters from the search string. It's not hard to think of examples of them occurring as part of valid entity names in our universe -- she got an A, Plan B From Outer Space, Vitamin C, etc.

An alternative strategy might be to trust the user to enter a valid search string and simply warn them that the quality of the answer they get will depend on the quality of their input.

Regards,
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux