如何提取中文字符,并算出该字符的位置?

madcatw madcatw 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
字符串1:一?二? //中文的问号
字符串2:?一?二 //英文的问号
字符串3:一 二 //中间有空格

php如何匹配出以上字符串里的中文文字?并求出该字符的位置
搞了半天搞不定,以下我的代码,大家别笑话

$k1 = "";
$k2 = "";
$k3 = "";
$k4 = "";
if(ord(substr($this->Keywords,1,1))>127)
{
$k1 = substr($this->Keywords,0,2);
}else {$k1=false;}
if(ord(substr($this->Keywords,2,1))>127)
{
$k2 = substr($this->Keywords,2,2);
}else {$k2=false;}
if(ord(substr($this->Keywords,3,1))>127)
{
$k3 = substr($this->Keywords,3,2);
}else {$k3=false;}
if(ord(substr($this->Keywords,4,1))>127)
{
$k4 = substr($this->Keywords,4,2);
}else {$k4=false;}
...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
madcatw
基础编程 21,889 成员 140,329 内容