php - preg_match with UTF8 -


i have string:

$string = 'this test'; 

and array of words:

$array = array('test','example','blahblah'); 

i want $string, , see if there of words of $array in or not:

$string_arr = explode(' ', $string); foreach($string_arr $value){     if (preg_match("/\b$value\b/iu", $array))         return true; } 

as see, used 'u' flag utf-8 support, wired thing works on wamp(localhost), on real server on centos it's not working, googled , found this: http://chrisjean.com/2009/01/31/unicode-support-on-centos-52-with-php-and-pcre/

but don not have access server upgrade rpm, how should it?

thanks in advance


anybody come solution? appreciate help.

i'm not sure if can simpler this: array_intersect($array,explode(' ',$string)); check if returned array has value , tell if of words in $array in $string. following tested , works.

if( count(array_intersect($array,explode(' ',$string))) > 0 ) {     echo 'we have match!'; } 

for sake of having full code block...

$string = 'this test'; $array = array('test','example','blahblah'); $checked_array = array_intersect($array,explode(' ',$string));  if( count($checked_array) > 0) {     echo 'the following words matched: '.implode(', ',$checked_array); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -