PHP ctype (Character type) Functions

PHP provides some of the built-in functions, which are used to verify the characters in the string i.e. to check whether a string contains the characters of specific types.

Table of Contents

Here, is the list of the PHP ctype functions -

FunctionsDescriptions
ctype_alnum()Checks whether given string contains all alphabets or numbers
ctype_alpha()Checks whether given string contains all alphabets
ctype_digit()Checks whether given string contains all digits
ctype_space()Checks whether given string contains spaces (whitespaces, tab, new line etc)
ctype_lower()Checks whether given string contains all lowercase characters
ctype_upper()Checks whether given string contains all uppercase characters
ctype_punct()Checks whether given string contains all punctuation characters
ctype_xdigit()Checks whether given string contains all hexadecimal digits
ctype_print()Checks whether given string contains all printable characters
ctype_graph()Checks whether given string contains all printable characters expect space
ctype_cntrl()Checks whether given string contains all control characters

Example

In this PHP example, we are using some of the characters type functions.

<?php
echo (ctype_alnum("Hello123")."\n");
echo (ctype_alpha("Helloworld")."\n");
echo (ctype_digit("01234")."\n");
echo (ctype_space("\r\n \t")."\n");
echo (ctype_lower("helloworld")."\n");
echo (ctype_upper("HELLOWORLD")."\n");
echo (ctype_punct("!@#~*&(){}")."\n");
echo (ctype_xdigit("aaff01290")."\n");
echo (ctype_print("Hello world!")."\n");
echo (ctype_graph("Hello123!@#")."\n");
echo (ctype_cntrl("\x00\x1F\x7F\r\n")."\n");	
?>

Output

1
1
1
1
1
1
1
1
1
1
1


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.