PHP:删除unicode文本中少于3个字符的单词 [英] PHP : Remove words less than 3 characters in unicode text

查看:70
本文介绍了PHP:删除unicode文本中少于3个字符的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这些正则表达式删除少于3个字符的单词:

I use these regex to remove words less than 3 characters :

$str = preg_replace("!\\b\\w{1,3}\\b!", "", $str);  

$rdu = "/\b[^\b]{1,2}\b/";
$str = preg_replace($rdu , " ", " " . $str . " "); 

但是以unicode文本返回我:

but in unicode text return me :

� �� �� �������� ��� �� � �� �� �������� ��� �� 
....

是否可以使用正则表达式来删除Unicode中少于3个字符的单词

is there any way with or without regex to remove words less than 3 characters in unicode text?

THXA

推荐答案

使用 u 修饰符,支持UTF-8

Use the u modifier for UTF-8 support:

/\b\w{1,2}\b/u

这篇关于PHP:删除unicode文本中少于3个字符的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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