• PHP Help PHP Coding
  • [RESOLVED] preg_match not working if pattern or subject contain extended characters

Hello all

I hope someone can help me with this. I think the problem may be a bug in PHP.

This is my line of code:

if (preg_match("/^".preg_quote($GLOBALS['lang']['url-search-advanced'], '/').".*$/i", $_SERVER['REQUEST_URI']))

This works fine if the following variables are used:
$GLOBALS['lang']['url-search-advanced'] = "/search/advanced/"
$_SERVER['REQUEST_URI'] = "/search/advanced/"

However it does not work if the following variables are used:
$GLOBALS['lang']['url-search-advanced'] = "/buscar/búsqueda-avanzada/"
$_SERVER['REQUEST_URI'] = "/buscar/búsqueda-avanzada/"

So the problem is only occurring if the strings have extended characters.

I am using PHP 5.3.19.

Is this a bug or am I making a mistake somewhere?

Thank you for your advice.

    I believe you need to use the u modifier to allow these characters to work.

      I agree with Derokorian - give the lowercase 'u' modifier a shot. For reference, see the manual page [man]reference.pcre.pattern.modifiers[/man] (search for PCRE_UTF8).

        Write a Reply...