Label to match accented characters

There are shortcuts in the regular expression, such as \wor a-z.

In the same way, is there an alternative to writing all the desired accented characters (e.g. conversion [éèàêâûôîùÈ...]to )?

+4
source share
1 answer

For instance:

$t = "Normal text éèàêâûôîùÈ more text";

preg_match_all('/[^\P{Latin}\x00-\x80]+/u', $t, $m);
print_r($m);

Result:

Array
(
    [0] => Array
        (
            [0] => éèàêâûôîùÈ
        )

)

Basically, it selects all the "Latin" characters (= letters), except those that are in the lower ascii range (= a..z). Not sure if this can be called a "shortcut" though;)

+2
source

Source: https://habr.com/ru/post/1539410/


All Articles