English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP ctype_alnum() Function Usage and Example

PHP Ctype Function Manual

The ctype_alnum() function checks if the string is composed entirely of letters and/or numbers characters.

Syntax

ctype_alnum(\$text);

Definition and Usage

It checks whether all characters in the provided string are letters and/or numbers.

In the standard C language environment, letters are only [A-Za-z], this function is equivalent to preg_match('/^[a-z0-9]+$/iD ', $text).

Parameter

Serial NumberParameters and Description
1

text(Required)

The string to be checked

Return Value

If each character in the text is a letter or number, it returns TRUE, otherwise it returns FALSE.

Online Example

Traverse the array elements to check if they are all alphanumeric

<?php
   \$strings = array('hello', 'foo!#$bar');
   
   foreach (\$strings as \$example) {
      if (ctype_alnum(\$example)) {
         echo "\$example is composed of letters or numbers.\n";
      }else {
         echo "\$example is not entirely letters or numbers.\n";
      }
   }
?>
Test and see‹/›

Output Result:

hello is composed of letters or numbers.
foo!#$bar is not entirely letters or numbers.

PHP Ctype Function Manual