The PHP Function Ctype_Print
PHP has a built-in function called ctype_print that checks whether all the characters in the string are printable. This is a really useful function because it ensures that any input from the user will actually cause something to be printed on the screen, including all alphabets, numbers and special characters. It also checks for any characters that cannot be printed on the screen, like control characters and line breaks.
If you’ve got a lot of data that may or may not be expected, it’s a good idea to run this test on the data before sending it to the web server. This will make sure that you don’t send the wrong data to your clients, and that all the data stored in your database is clean.
The ctype_print() function is part of the ctype extension, which is available by default with PHP 4.2 and above. It is one of the tens of thousands of built-in functions that come with the language, and it helps you check whether the characters you’re getting in your input are the ones you expect.
Each of the ctype functions checks for different types of characters, so there’s a good chance that you’ll find the right one for the task at hand. Some of the most popular ones include ctype_alnum() (checks for alphanumeric characters, upper or lower case), ctype_digit() (checks for numeric characters (0-9 and no special characters), and ctype_cntrl() (checks for control characters).