Maison  >  Article  >  développement back-end  >  从C/C++迁移到PHP——判断字符类型的函数_PHP教程

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

WBOY
WBOYoriginal
2016-07-21 16:02:15919parcourir


  在C/C++中,头文件ctype.h中定义了关于字符类型一组宏,可以得到给定字符的类型。
而PHP中没有相关函数。前些天发现在www.mm4.de下载的PHP中提供了一个名为php_ctype.dll的扩展库,
加载后发现提供一部分此类的函数,特整理出来供大家参考。
  在PHP中正确加载php_ctype.dll文件后,用可以看到以下信息:
      ctype
  ctype functions enabled (experimental)
然后就可以使用它所提供的函数了。所有函数的用法同C/C++基本相同,区别在于在C/C++中函数的参数是
字符型(char),而在PHP中函数的参数可以是字符串(string)。例如:

$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)

【本文版权归作者凡草0515与奥索网共同拥有,如需转载,请注明作者及出处】     

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/316621.htmlTechArticle在C/C++中,头文件ctype.h中定义了关于字符类型一组宏,可以得到给定字符的类型。 而PHP中没有相关函数。前些天发现在www.mm4.de下载的PHP中...
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn