Why does this PHP regex not match for accented characters?
I'm writing a quick PHP page, and I need to ignore any Strings with accented characters. I am using this preg_match() string on each word:
"[ÀÁÅÃÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ]"
(Quite a brute force method I know, but apparently [a-zA-Z] can match for accented characters)
But the functi开发者_Go百科on never seems to return true when it searches Strings with accented characters (Examples: "cheap…", "gustarÃa"...)
I haven't used Regex before, so please point out any stupid mistakes I'm making here!
PHP regexes need delimiters, like so:
preg_match('/[ÀÁÅÃÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ]/', "gustarÃa");
Note that it's also preferable to use single quotes for regex because the dollar sign could be mistaken by php as a variable.
精彩评论