Page 1 of 1

Advanced search

Posted: Fri Jul 18, 2008 6:07 am
by AudiS2
Task:
Replace a string using advanced matching

Example:
$needle="pretty blue day"
$haystack="It was blue and pretty day yesterday"

Match "blue and pretty day", meaning the $needle can be permuted and additional words can be inserted in between (one or two words max, if possible this would be a setting).

Re: Advanced search

Posted: Fri Jul 18, 2008 6:39 am
by dhrosti
use explode() to break up the words, then str_replace() to replace each one in the string?

Re: Advanced search

Posted: Sat Jul 19, 2008 1:16 pm
by AudiS2
dhrosti wrote:use explode() to break up the words, then str_replace() to replace each one in the string?
I can explode them but I need to replace the whole matched phrase afterward - "blue and pretty day" in the example is replaced with something. I have trouble joining these up.