Amos Vryhof wrote:
Ok, My example was pretty bad.

I was just looking for an easier/more optimal way to look for something
along the lines of
"word1*word2*word3*word4" rather than "word1 word2 word3 word4" as it
currently does.

Actually, I think I have an idea for a way to do what I want without a
regular expression.... I'll have to see how fast it is though before
actually using it.

Not guaranteed to work at all but if you really want to use a regex you could do something like this:


$words = array('word1', 'word2', 'word3');

$search = '%';
foreach ($words as $word) {
  $search .= '\\\b'.preg_quote($word, '%') . '\\\b.*?';
}
$search .= '%is';

preg_match($search, $string, $found_matches);


So you should end up with something like:

preg_match('%\bword1\b.*?\bword2\b.*?\bword3\b%is', $string, $found_matches);


See http://www.php.net/preg_quote and http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php and http://www.php.net/manual/en/reference.pcre.pattern.syntax.php

--
Postgresql & php tutorials
http://www.designmagick.com/

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

Reply via email to