PHP 中的 ctype_alnum() 函數用於檢查給定字符串/文本的所有字符是否為字母數字。如果所有字符都是字母數字,則返回 TRUE,否則返回 FALSE。
用法:
bool ctype_alnum ($text)
使用的參數:
- $text:它是一個強製參數,用於指定字符串。
例子:
Input :Geeks Output:Yes Explanation:String "Geeks" is alphanumeric. Note: Read Standard c local letter. Input :'%%%Contribute_article on GFG!!!' Output:No Explanation:String contains Special characters.
Note: Except string or digit, if we input anything then it will return FALSE.
以下示例程序旨在說明 ctype_alnum() 函數。
節目:1
驅動代碼 ctype_alnum()() 函數以便更好地理解。
<?php
// PHP program to check given string is
// all characters are alphanumeric
$string = 'GeeksforGeeks';
if ( ctype_alnum($string))
echo "Yes\n";
else
echo "No\n";
?>
輸出:
Yes
節目:2驅動 ctype_alnum() 函數的代碼,其中輸入將是字符串整數數組,帶有特殊符號的字符串。
<?php
// PHP program to check given string is
// all characters are alphanumeric
$strings = array(
'Geeks',
'geek@gmail.com',
'2018',
'GFG2018',
'a b c ',
'@!$%^&*()|2018'
);
// Checking above given four strings
// by used of ctype_alnum() function .
foreach ($strings as $test) {
if (ctype_alnum($test))
echo "Yes\n";
else
echo "No\n";
}
?>
輸出:
Yes No Yes Yes No No
參考資料:http://php.net/manual/en/function.ctype-alnum.php
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | ctype_alnum() (Check for Alphanumeric)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。