PHP: How to remove all non printable characters from string

2 minutes read

If you want to strip line feeds, carriage returns, and tabs you can use:

 

=>Note that you must use single quotes for the above two examples.

If you want to strip everything except basic printable ASCII characters (all the example characters above will be stripped) you can use:

 

Facebook Twitter LinkedIn Telegram Whatsapp

Related Posts:

What is PHP ? PHP stands for Hypertext Preprocessor and is a server-side language. PHP allows web developers to create dynamic content that interacts with databases. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becom...
How can I find non-ASCII characters in MySQL?   Query to find data as  “ASCII”, SELECT * FROM tableName WHERE NOT columnToCheck REGEXP '[A-Za-z0-9]'; 1 SELECT * FROM tableName WHERE NOT columnT...
Some times we need the visitor’s IP address for validation, security, spam prevention etc. Getting the Visitor’s IP address is very easy in PHP. We can get the Internet Protocol (IP) address of any visitor by using PHP. Get Clients IP address using PHP script ...