我正在尝试为PHP中的名称编写一个合理宽松的验证器,我的第一次尝试包含以下模式:
// unicode letters, apostrophe, hyphen, space
$namePattern = "/^([\\p{L}'\\- ])+$/";
Run Code Online (Sandbox Code Playgroud)
这最终传递给了一个电话preg_match().据我所知,这适用于你的vanilla ASCII字母表,但似乎惹上像Ă或张这样的尖锐字符.
这个模式本身有什么问题吗?也许我期待\p{L}比我想的更多的工作?
或者它与传入输入的方式有关?我不确定它是否相关,但我确实确保在表单页面上指定UTF8编码.
我在URI中遇到了(德语)特殊字符的问题,并希望尝试使用RegEx Route和UTF-8 的PCRE模式修饰符来解决它u.
'router' => array(
'routes' => array(
// ...
'city' => array(
'type' => 'regex',
'options' => array(
'regex' => '/catalog/(?<city>[a-zA-Z0-9_-äöüÄÖÜß]*)\/u',
'defaults' => array(
'controller' => 'Catalog\Controller\Catalog',
'action' => 'list-sports',
),
'spec' => '/catalog/%city%',
),
'may_terminate' => true,
),
),
),
Run Code Online (Sandbox Code Playgroud)
但是当我设置它时,路径就会停止工作(错误404) - 既不是URI也不是没有特殊字符的URI.
如何正确设置修改器?