我希望我的路由支持波斯字符,但是當在正則表達式路徑中使用x {600} - \ x {6FF}時,應用會給我一個404錯誤(找不到頁面)zend框架2使用UTF-8正則表達式路由
我ZF2路由配置:
'result' => array(
'type' => 'segment',
'options' => array(
'route' => '/Result[/:name]',
'constraints' => array(
'name' => '[\sa-zA-Z0-9_.-x{600}-\x{6FF}]*',
),
'defaults' => array(
'controller' => 'Result',
'action' => 'index',
),
),
),
,我添加u
結束在Zend的\的mvc \路由器正則表達式的\ HTTP \ Segment.php
if ($pathOffset !== null) {
$result = preg_match('(\G' . $regex . ')u', $path, $matches,null, $pathOffset);
} else {
$result = preg_match('(^' . $regex . '$)u', $path, $matches);
}
我的網址是這樣的:
http://localhost/test/Result/A.8.کلمه
嘗試''[\ sa-zA-Z0-9 _。\ x {600} - \ x {6FF} - ] *''。 –
我嘗試使用上面的代碼,但給我404錯誤 –
看來你需要將'rawurldecode($ path);'傳遞給'preg_match'。請嘗試使用上述正則表達式。 –