Question

My string is in a foreign language. I use the following regular 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?

Was it helpful?

Solution

Try adding the u modifier:

$cont = preg_match_all("/.{0,80}[^\s]*?".preg_quote($word)."[^\s]*?.{0,80}/siu",$str,$matched);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top