Stewart Robinson Stewart Robinson - 1 year ago 80
PHP Question

PHP: How to remove all non printable characters in a string?

I imagine I need to remove chars 0-31 and 127,

Is there a function or piece of code to do this efficiently.

Answer Source

Something like this should do it

$string = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $string);

It matches anything in range 0-31, 128-255 and removes it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download