Home » Php » PHP How to Remove/Replace Unknown question mark diamond characters

PHP How to Remove/Replace Unknown question mark diamond characters

Posted by: admin July 12, 2020 Leave a comment

Questions:

I am using PHP to access data on old machines and output them.

Putty shows:

▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒NONE.
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒

Its the weird formatting in a attempt to show data in a more clean way

PHP echo-ed chrome shows:

������
�NONE. �
������

I have tried:

$Str1 = str_replace("▒","",$Str1);

But it doesn’t filter them out.
The output is already utf 8.

Does anyone know how to filter out these things? Maybe identify what � is to php?

How to&Answers:

Try this:

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