检查字符串是否仅包含英文字母,数字和符号(Check if string contains only English alphabets , digits and symbols)
我想检查只包含英文字母,数字和符号的字符串。我试过下面的代码,但它只适用于所有字符都是不同的语言。
if(strlen($string) != mb_strlen($string, 'utf-8')) { echo "o English words "; } else { echo "only english words"; }例如
1. hellow hi 12#!@#!@#()#@# -- true 2. ព្រាប សុវ ok yes #@# - false . this is good 12 - true 4. ព្រាប -- falseps:我的问题不重复,因为其他问题只涵盖字母和符号,我的覆盖符号也是如此
I want to check for string that contains only english alphabets , digits and symbols.I tried below code but it works only when all the characters are different language.
if(strlen($string) != mb_strlen($string, 'utf-8')) { echo "o English words "; } else { echo "only english words"; }For example
1. hellow hi 12#!@#!@#()#@# -- true 2. ព្រាប សុវ ok yes #@# - false . this is good 12 - true 4. ព្រាប -- falsep.s : my question is not duplicate because other questi only cover alphabets and symbols , mine covers symbol too
最满意答案
确定一个字符串是否只是可打印的ASCII工作? 如果是这样,你可以使用这个正则表达式:
[ -~]http:///blog/my-favorite-regex/
如果您还需要非ASCII字符,则可以使用Wikipedia页面获取所需的特定unicode格式:
https://en./wiki/List_of_Unicode_characters#Control_codes
Would determining if a string is just printable ASCII work? If so you can use this regex:
[ -~]http:///blog/my-favorite-regex/
If you need non ASCII characters as well than you can use the Wikipedia page to get the specific unicode formats that you need:
https://en./wiki/List_of_Unicode_characters#Control_codes
#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格
推荐阅读
留言与评论(共有 10 条评论) |
本站网友 华城新都 | 5分钟前 发表 |
则可以使用Wikipedia页面获取所需的特定unicode格式: https | |
本站网友 迁安美食 | 13分钟前 发表 |
///blog/my-favorite-regex/ If you need non ASCII characters as well than you can use the Wikipedia page to get the specific unicode formats that you need | |
本站网友 理念的意思 | 8分钟前 发表 |
//en./wiki/List_of_Unicode_characters#Control_codes Would determining if a string is just printable ASCII work? If so you can use this regex | |
本站网友 自由城 | 15分钟前 发表 |
数字和符号(Check if string contains only English alphabets | |
本站网友 苏宁老总 | 7分钟前 发表 |
digits and symbols.I tried below code but it works only when all the characters are different language. if(strlen($string) != mb_strlen($string | |
本站网友 浮雕设计 | 26分钟前 发表 |
你可以使用这个正则表达式: [ -~] http | |
本站网友 西部院线 | 24分钟前 发表 |
[ -~] http | |
本站网友 佛山市一 | 20分钟前 发表 |
'utf-8')) { echo "o English words "; } else { echo "only english words"; } 例如 1. hellow hi 12#!@#!@#()#@# -- true 2. ព្រាប សុវ ok yes #@# - false . this is good 12 - true 4. ព្រាប -- false ps:我的问题不重复 | |
本站网友 碧云二手房 | 9分钟前 发表 |
'utf-8')) { echo "o English words "; } else { echo "only english words"; } For example 1. hellow hi 12#!@#!@#()#@# -- true 2. ព្រាប សុវ ok yes #@# - false . this is good 12 - true 4. ព្រាប -- false p.s |