從C/C++遷移到PHP——判斷字符分類的函數
發表時間:2023-08-12 來源:明輝站整理相關軟件相關文章人氣:
[摘要]在C/C++中,頭文件ctype.h中定義了關于字符類型一組宏,可以得到給定字符的類型。 而PHP中沒有相關函數。前些天發現在www.mm4.de下載的PHP中提供了一個名為php_ctype.dl...
在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)