從C/C++遷移到PHP——判斷字符類型的函數

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

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *