国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php ctype函數(shù)中文翻譯和示例

2024-09-04 11:43:21
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php ctype函數(shù)中文翻譯和示例,相關函數(shù)示例列出了多個,需要的朋友可以參考下。

PHP Ctype擴展是PHP4.2開始就內建的擴展,注意,Ctype系列函數(shù)都只有一個字符串類型參數(shù),它們返回布爾值。

  1. $str = "0.1123"
  2. //檢查字符串所有字符是否為數(shù)字 
  3. echo "ctype_digit:" . ctype_digit($str);  //空 
  4. //檢測是否為數(shù)字字符串,可為負數(shù)和小數(shù) 
  5. echo "is_numberic:" . is_numeric($str); //1 

從上面可以看出ctype_digit()和is_numberic()的區(qū)別。

中文翻譯

Ctype函數(shù)是PHP內置的字符串體測函數(shù)。主要有以下幾種

ctype_alnum -- Check for alphanumeric character(s)

檢測是否是只包含[A-Za-z0-9]

ctype_alpha -- Check for alphabetic character(s)

檢測是否是只包含[A-Za-z]

ctype_cntrl -- Check for control character(s)

檢查是否是只包含類是“/n/r/t”之類的字 符控制字符

ctype_digit -- Check for numeric character(s)

檢查時候是只包含數(shù)字字符的字符串(0-9)

ctype_graph -- Check for any printable character(s) except space

檢查是否是只包含有可以打印出來的字符(除了空格)的字符串

ctype_lower -- Check for lowercase character(s)

檢查是否所有的字符都是英文字母,并且都是小寫的

ctype_print -- Check for printable character(s)

檢查是否是只包含有可以打印出來的字符的字符串

ctype_punct -- Check for any printable character which is not whitespace or an alphanumeric character

檢查是否是只包含非數(shù)字/字符/空格的可打印出來的字符

ctype_space -- Check for whitespace character(s)

檢查是否是只包含類是“ ”之類的字符和空格

ctype_upper -- Check for uppercase character(s)

檢查是否所有的字符都是英文字母,并且都是大寫的

ctype_xdigit -- Check for character(s) representing a hexadecimal digit

檢查是否是16進制的字符串,只能包括 “0123456789abcdef”

有示例的喲

我們平常在遇到要對一些表單做簡單過濾的時候,往往不太愿意寫正則,而且在效率上,正則也是影響PHP運行速度的原因之一,所以在能不試用正則的時候盡量不試用正則。幸好PHP已經為我們考慮到了這一點,給我提供了Ctype函數(shù)。下面對一些Ctype函數(shù)做一些簡單介紹,以備用:

1、ctype_alnum — Check for alphanumeric character(s)   檢查字符串中只包含數(shù)字或字母,相當于正則[A-Za-z0-9].   有返回值。成功時返回TRUE,失敗為FALSE;

  1. <?php   
  2. $strings = array('AbCd1zyZ9''foo!#$bar');   
  3. foreach ($strings as $testcase) {   
  4.     if (ctype_alnum($testcase)) {   
  5.         echo "The string $testcase consists of all letters or digits./n"; // 輸出The string AbCd1zyZ9 consists of all letters or digits.   
  6.     } else {   
  7.         echo "The string $testcase does not consist of all letters or digits./n"; // 輸出 The string foo!#$bar does not consist of all letters or digits.   
  8.     }   
  9. }   
  10. ?>   

2、ctype_alpha — Check for alphabetic character(s)  檢查字符串中只包含字母。  成功時返回TRUE,失敗為FALSE;

  1. <?php   
  2. $strings = array('KjgWZC''arf12');   
  3. foreach ($strings as $testcase) {   
  4.     if (ctype_alpha($testcase)) {   
  5.         echo "The string $testcase consists of all letters./n"; // 輸出 The string KjgWZC consists of all letters.   
  6.     } else {   
  7.         echo "The string $testcase does not consist of all letters./n";<span style="white-space:pre">   </span>// 輸出 The string arf12 does not consist of all letters.   
  8.     }   
  9. }   
  10. ?> 

3、ctype_cntrl — Check for control character(s)    檢查字符串中是否只包含" '/n' '/r' '/t' " 這樣的控制字符。

  1. <?php   
  2. $strings = array('string1' => "/n/r/t"'string2' => 'arf12');   
  3. foreach ($strings as $name => $testcase) {   
  4.     if (ctype_cntrl($testcase)) {   
  5.         echo "The string '$name' consists of all control characters./n"; // 輸出 The string 'string1' consists of all control characters.   
  6.     } else {   
  7.         echo "The string '$name' does not consist of all control characters./n"; // The string 'string2' does not consist of all control characters.   
  8.     }   
  9. }   
  10. ?>    

4、ctype_digit — Check for numeric character(s) 檢查字符串中是否只包含數(shù)字

  1. <?php   
  2. $strings = array('1820.20''10002''wsl!12');   
  3. foreach ($strings as $testcase) {   
  4.     if (ctype_digit($testcase)) {   
  5.         echo "The string $testcase consists of all digits./n";   
  6.     } else {   
  7.         echo "The string $testcase does not consist of all digits./n";   
  8.     }   
  9. }   
  10. ?> 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 大余县| 桃源县| 高淳县| 平罗县| 浮梁县| 绥江县| 武安市| 昌乐县| 玉屏| 长子县| 新化县| 南雄市| 杭州市| 桐柏县| 平利县| 通海县| 扬州市| 昌黎县| 玉林市| 武强县| 中山市| 新巴尔虎左旗| 遂昌县| 东源县| 石家庄市| 深州市| 涿鹿县| 和龙市| 汝南县| 扶沟县| 衢州市| 日土县| 罗定市| 西乡县| 长沙县| 邮箱| 宜兴市| 廊坊市| 渭南市| 富源县| 萨迦县|