PHPpreg_matchË不起作用

时间:2016-12-30 04:43:29

标签: php preg-match

我有以下preg_match但我无法从字符串中获取Ë。

$title = 'This is blablabla BRAZILIË';
preg_match_all('/\b([A-Z]+)\b/', $title, $matches);

输出:

Array
(
    [0] => Array
    (
        [0] => BRAZILI
    )

我想:

Array
(
[0] => Array
    (
        [0] => BRAZILIË
    )

2 个答案:

答案 0 :(得分:3)

对大写字母\p{Lu}使用unicode属性,不要忘记u修饰符:

$title = 'This is blablabla BRAZILIË';
preg_match_all('/\b(\p{Lu}+)\b/u', $title, $matches);
print_r($matches);

根据评论,这是一种小写多字节字符的方法,请参阅mb_strtolower

$title = 'This is blablabla BRAZILIË';
preg_match_all('/\b(\p{Lu}+)\b/u', $title, $matches);
$res = ucfirst(mb_strtolower($matches[0][0]));
echo "$res\n";

<强>输出:

Brazilië

答案 1 :(得分:0)

您需要使用unicode匹配。试试这个:

preg_match_all("/\b([A-Z\x{c0}-\x{ff}]+)\b/u", $title, $matches);

根据您的使用情况,您可能希望通过查看此表来扩展字符:http://www.utf8-chartable.de/

相关问题