Advanced search

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AudiS2
Forum Newbie
Posts: 5
Joined: Thu Feb 28, 2008 6:02 pm

Advanced search

Post 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).
User avatar
dhrosti
Forum Commoner
Posts: 90
Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK

Re: Advanced search

Post by dhrosti »

use explode() to break up the words, then str_replace() to replace each one in the string?
AudiS2
Forum Newbie
Posts: 5
Joined: Thu Feb 28, 2008 6:02 pm

Re: Advanced search

Post 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.
Post Reply