views:

41

answers:

1

My string is in foreign language, i use the following expression

$str = 'մի քանի Բառ ձեր մասին';
$word = 'բառ';

$cont = preg_match_all("/.{0,80}[^\s]*?".preg_quote($word)."[^\s]*?.{0,80}/si",$str,$matched);
print_r($matched);//returns Array ( [0] => Array ( ) ) ..

.

but if i set

$word = "Բառ";//returns Array ( [0] => Array ( [0] => մի քանի Բառ ձեր մասին ) )  

what can i do, to be able to use i modifier in foreign languages too?

Thanks

+5  A: 

Try adding the u modifier:

$cont = preg_match_all("/.{0,80}[^\s]*?".preg_quote($word)."[^\s]*?.{0,80}/siu",$str,$matched);
Alix Axel
perfect. Thanks much. Could you explain why u modifier has influance on language? as i know, it inverts the greediness only?
Syom
@Syom: `U` (uppercase) is for an non-greedy match and `u` (lowercase) is for interpreting the pattern as UTF-8 encoded. See http://php.net/reference.pcre.pattern.modifiers.
Gumbo