Symfony2 Routing Requirements: how to enable UTF-8 mode?

只谈情不闲聊 提交于 2019-12-08 00:35:06

问题


I want to use the following regex as an requirement for symfony2 routing:

/^[ \x{00C0}-\x{01FF}a-zA-Z'\-]+$/u

The special thing here is to enable the utf8-mode with the u-modifier at the end. How to pass this /u to requirement-section of a symfony routing.yml?

Our current routing.yml looks like that:

search_by_name:
    path:     /search/name/{name}-4/{page}/{limit}
    defaults: { _controller: SearchBundle:SearchByName:index, page: 0, limit: 8 }
    requirements:
        name: "[äüößÄÖÜ´\"`èéa-zA-Z\-]+"

Now we want to apply the pattern mentioned above:

    requirements:
        name: "[ \x{00C0}-\x{01FF}a-zA-Z'\-]+"  <-- "u" is missing

Where to pass the "u"? Just adding the character at the end will result in the following error:

Warning: preg_match(): Compilation failed: character value in \x{...} sequence is too large at offset 61


回答1:


The Symfony Routing component doesn't support fully Unicode ; basically because it doesn't use multibyte-safe string functions internally. Unexpected issues can occurs when using such flags.

Progress in Unicode support in the component is tracked in the following issue: https://github.com/symfony/symfony/issues/5236



来源:https://stackoverflow.com/questions/32285152/symfony2-routing-requirements-how-to-enable-utf-8-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!