<?php
$result = "\xC2°Freen\x18 ew°\x90ɮ\x7F";
//$result="a\xC2";
//$result = preg_replace('~[\x{0000}-\x{000F}\x{007F}-\x{00a0}]~S', '', $result);
$result = preg_replace('~[\x{0000}-\x{000F}\x{007F}-\x{00a0}]~', '?', $result);
$string = "°Freen\x18 ew°\x90ɮ\x7F\xc2";
$string = preg_replace("#[\x09\x0A\x0D\x20-\x7E]#" ,"",$string); // ASCII
$string = preg_replace("#[\xC2-\xDF][\x80-\xBF]#" ,"",$string); // non-overlong 2-byte
$string = preg_replace("#\xE0[\xA0-\xBF][\x80-\xBF]#" ,"",$string); // excluding overlongs
$string = preg_replace("#[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}#","",$string); // straight 3-byte
$string = preg_replace("#\xED[\x80-\x9F][\x80-\xBF]#" ,"",$string); // excluding surrogates
$string = preg_replace("#\xF0[\x90-\xBF][\x80-\xBF]{2}#","",$string); // planes 1-3
$string = preg_replace("#[\xF1-\xF3][\x80-\xBF]{3}#" ,"",$string); // planes 4-15
$string = preg_replace("#\xF4[\x80-\x8F][\x80-\xBF]{2}#","",$string); // plane 16
//reject overly long 2 byte sequences, as well as characters above U+10000 and replace with ?
$result= preg_replace(
'/[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})/S',
'', $result );
if($result == "\xC2")
echo 'fuck';
echo $result;
preferences:
41.93 ms | 402 KiB | 5 Q