Preg_Match特殊字符,如土耳其语和其他 [英] preg_match special character like Turkish and other

查看:21
本文介绍了Preg_Match特殊字符,如土耳其语和其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来获取URL匹配,但当我使用一些特殊字符,如土耳其语时,例如ülkeaşk,我无法获得任何请求。但如果我使用ulkeask,则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];
}

Utf

您可能需要使用u修饰符来告诉preg_match将字符串视为推荐答案-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; //ülke

这篇关于Preg_Match特殊字符,如土耳其语和其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆