php检查字符串中是否包含7位GSM字符的方法


Posted in PHP onMarch 17, 2015

本文实例讲述了php检查字符串中是否包含7位GSM字符的方法。分享给大家供大家参考。具体分析如下:

下面的代码检查一个字符串是否包含任何7位GSM字符。它对短信平台上工作的人非常有用。

<?php
function check_gsm($str)
{
  $arr = array(
"0x00", "0x01", "0x02", "0x03", "0x04", 
"0x05","0x06","0x07","0x08","0x09",
"0x0A","0x0B","0x0C","0x0D","0x0E","0x0F","0x10","0x11","0x12","0x13",
"0x14","0x15","0x16","0x17","0x18","0x19","0x1A","0x1B","0x1B0A",
"0x1B14","0x1B28","0x1B29","0x1B2F","0x1B3C","0x1B3D","0x1B3E",
"0x1B40","0x1B65","0x1C","0x1D","0x1E","0x1F","0x20","0x21","0x22",
"0x23","0x24","0x25","0x26","0x27","0x28","0x29","0x2A","0x2B","0x2C",
"0x2D","0x2E","0x2F","0x30","0x31","0x32","0x33","0x34","0x35","0x36",
"0x37","0x38","0x39","0x3A","0x3B","0x3C","0x3D","0x3E","0x3F","0x40",
"0x41","0x42","0x43","0x44","0x45","0x46","0x47","0x48","0x49","0x4A",
"0x4B","0x4C","0x4D","0x4E","0x4F","0x50","0x51","0x52","0x53","0x54",
"0x55","0x56","0x57","0x58","0x59","0x5A","0x5B","0x5C","0x5D","0x5E",
"0x5F","0x60","0x61","0x62","0x63","0x64","0x65","0x66","0x67","0x68",
"0x69","0x6A","0x6B","0x6C","0x6D","0x6E","0x6F","0x70","0x71","0x72",
"0x73","0x74","0x75","0x76","0x77","0x78","0x79","0x7A","0x7B","0x7C",
"0x7D","0x7E","0x7F");
  $strl = strlen($str);
  for ($i = 0;$i < $strl; $i++)
  {
    $char = '0x' . bin2hex(substr($str,$i,1));
    $pos = in_array($char,$arr);
    if ($pos == 1)
    {
      $j++;
    }
  }
  if ($j < $strl)
  {
    return false;
  }
  else
  {
    return true;
  }
}
?>

希望本文所述对大家的php程序设计有所帮助。

PHP 相关文章推荐
php开发留言板的CRUD(增,删,改,查)操作
Apr 19 PHP
用来解析.htpasswd文件的PHP类
Sep 05 PHP
ThinkPHP3.1.3版本新特性概述
Jun 19 PHP
php查找字符串出现次数的方法
Dec 01 PHP
PHP、Java des加密解密实例
Apr 27 PHP
php遍历树的常用方法汇总
Jun 18 PHP
php制作基于xml的RSS订阅源功能示例
Feb 08 PHP
laravel中命名路由的使用方法
Feb 24 PHP
老生常谈PHP位运算的用途
Mar 12 PHP
PHP实现简单的模板引擎功能示例
Sep 02 PHP
thinkphp5框架前后端分离项目实现分页功能的方法分析
Oct 08 PHP
laravel 操作数据库常用函数的返回值方法
Oct 11 PHP
php字符串分割函数用法实例
Mar 17 #PHP
[原创]php获取数组中键值最大数组项的索引值
Mar 17 #PHP
THINKPHP支持YAML配置文件的设置方法
Mar 17 #PHP
php判断数组中是否存在指定键(key)的方法
Mar 17 #PHP
php在数组中查找指定值的方法
Mar 17 #PHP
php中使用key,value,current,next和prev函数遍历数组的方法
Mar 17 #PHP
PHP实现获取客户端IP并获取IP信息
Mar 17 #PHP
You might like
《一拳超人》埼玉一拳下去,他们存在了800年毫无意义!
2020/03/02 日漫
怎样辨别一杯好咖啡
2021/03/03 新手入门
使用php来实现网络服务
2009/09/15 PHP
twig模板获取全局变量的方法
2016/02/05 PHP
PHP入门教程之数组用法汇总(创建,删除,遍历,排序等)
2016/09/11 PHP
Laravel获取当前请求的控制器和方法以及中间件的例子
2019/10/11 PHP
Javascript调用XML制作连动下拉列表框
2006/06/25 Javascript
js日期时间补零的小例子
2013/03/05 Javascript
不使用jquery实现js打字效果示例分享
2014/01/19 Javascript
JavaScript制作的可折叠弹出式菜单示例
2014/04/04 Javascript
Javascript堆排序算法详解
2014/12/03 Javascript
举例讲解JavaScript中将数组元素转换为字符串的方法
2015/10/25 Javascript
vue项目中用cdn优化的方法
2018/01/03 Javascript
代码分析vue中如何配置less
2018/09/28 Javascript
详解webpack打包vue项目之后生成的dist文件该怎么启动运行
2019/09/06 Javascript
js实现圆形显示鼠标单击位置
2020/02/11 Javascript
在Vue中实现随hash改变响应菜单高亮
2020/03/09 Javascript
vue实现简单加法计算器
2020/10/22 Javascript
Python简单计算文件MD5值的方法示例
2018/04/11 Python
Python实现的NN神经网络算法完整示例
2018/06/19 Python
Atom的python插件和常用插件说明
2018/07/08 Python
Win10下python 2.7.13 安装配置方法图文教程
2018/09/18 Python
python的pytest框架之命令行参数详解(下)
2019/06/27 Python
Python decimal模块使用方法详解
2020/06/08 Python
小白教你PyCharm从下载到安装再到科学使用PyCharm2020最新激活码
2020/09/25 Python
python中的时区问题
2021/01/14 Python
CSS3属性box-shadow使用详细教程
2012/01/21 HTML / CSS
纯CSS3实现自定义Tooltip边框涂鸦风格的教程
2014/11/05 HTML / CSS
6种非常炫酷的CSS3按钮边框动画特效
2016/03/16 HTML / CSS
使用CSS3来代替JS实现交互
2017/08/10 HTML / CSS
英国复古皮包品牌:Beara Beara
2018/07/18 全球购物
业务员岗位职责范本
2013/12/15 职场文书
考博专家推荐信
2014/05/10 职场文书
导游词之阳朔遇龙河
2019/12/16 职场文书
JS继承最简单的理解方式
2021/03/31 Javascript
css布局巧妙技巧之css三角示例的运用
2022/03/16 HTML / CSS