从C/C++迁移到PHP——判断字符类型的函数

来源:互联网 发布:人类知乎 编辑:程序博客网 时间:2024/06/07 19:29
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
在C/C++中,头文件ctype.h中定义了关于字符类型一组宏,可以得到给定字符的类型。
PHP中没有相关函数。前些天发现在www.mm4.de下载的PHP中提供了一个名为PHP_ctype.dll的扩展库,
加载后发现提供一部分此类的函数,特整理出来供大家参考。
  在PHP中正确加载PHP_ctype.dll文件后,用<?PHP PHPinfo();?>可以看到以下信息:
      ctype
  ctype functions enabled (experimental)
然后就可以使用它所提供的函数了。所有函数的用法同C/C++基本相同,区别在于在C/C++中函数的参数是
字符型(char),而在PHP函数的参数可以是字符串(string)。例如:

<?PHP
$string="123ADAADAD";
if(isalnum($string))
{
echo "只有大小写字母和数字!";
}

?>

附:PHP_ctype.dll支持的函数
bool isalnum(string)
bool isalpha(string)
bool iscntrl(string)
bool isdigit(string)
bool isgraph(string)
bool islower(string)
bool isprint(string)
bool ispunct(string)
bool isspace(string)
bool isupper(string)
bool isxdigit(string)
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击