我正在使用下面的代码来获取url匹配,但是当我使用一些特殊字符时,比如土耳其语,例如ülke,aşk,那么我无法获得任何请求。但是如果我使用ulke,ask,那么I就可以得到结果。
谁能告诉我这里的问题是什么?
$request_uri = 'https://www.weburl.com/hashtag/ulke'; // working fine
$request_uri = 'https://www.weburl.com/hashtag/ülke'; // no result
if (preg_match('~/(hashtag)/([[\w.-]+)~', $request_uri, $match)) {
$pageFor = $match[2];
}发布于 2021-04-10 03:01:10
您可能需要使用UTF修饰符来告诉preg_match将字符串视为u -8:
https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
$request_uri = 'https://www.weburl.com/hashtag/ülke';
if (preg_match('~/(hashtag)/([[\w.-]+)~u', $request_uri, $match)) {
$pageFor = $match[2];
}
echo $pageFor; //ülkehttps://stackoverflow.com/questions/67026794
复制相似问题