Press "Enter" to skip to content

Did you know about ctype* functions in php ?

Sharing is caring!

How many times have we written the regular expressions to check whether it only consists of alphabets or just numeric?

And how many time we were so sure about that expression will work exactly?

Wished, it was known to me before doing a lots of those stupid regular expression stuffs.

So, PHP has a set of ctype_ prefixed functions. And now we can stop doing those dirty regular expression stuffs we do with regular expression.

The functions provided by ctype extension check whether a character or string falls into a certain character class according to the current locale.

It is not much, but it would actually remove a lots of common issues we face.

  1. ctype_alnum — Check for alphanumeric character(s)
  2. ctype_alpha — Check for alphabetic character(s)
  3. ctype_cntrl — Check for control character(s)
  4. ctype_digit — Check for numeric character(s)
  5. ctype_graph — Check for any printable character(s) except space
  6. ctype_lower — Check for lowercase character(s)
  7. ctype_print — Check for printable character(s)
  8. ctype_punct — Check for any printable character which is not whitespace or an alphanumeric character
  9. ctype_space — Check for whitespace character(s)
  10. ctype_upper — Check for uppercase character(s)
  11. ctype_xdigit — Check for character(s) representing a hexadecimal digit

Source: PHP.NET

Everything is awesome.

Be First to Comment

    Leave a Reply

    Your email address will not be published.