Это способ, которым я хотел бы использовать:
$string = 'The mouse to nibble the cork from the bottle russia king.';
preg_match_all("/^(?=.*(cork))(?=.*(bottle))/i", $string, $matches);
print_r($matches);
Выход:
Array
(
[0] => Array
(
[0] =>
)
[1] => Array
(
[0] => cork
)
[2] => Array
(
[0] => bottle
)
)
Объяснение:
/ : regex delimiter
^ : begining of line
(?= : start lookahead
.* : 0 or more any character
(\bcork\b) : capture group #1 that contains "cork" with word boundaries
) : end of look ahead
(?= : start lookahead
.* : 0 or more any character
(\bottle\b) : capture group #2 that contains "bottle" with word boundaries
) : end of look ahead
/i : regex delimiter, case insensitive
Нужно ли проводить оценку в указанном порядке, или это нормально в любом порядке? – joncloud