preg_replace('/[x00-x1f]/','',htmlspecialchars($string));
if want to use strtoupper, use it before using htmlspecialchars otherwise it will not works
preg_replace('/[x00-x1f]/','',htmlspecialchars(strtoupper($string)));
for example,
'&' => '$amp;'
if use strtoupper after htmlspecialchars ‘$amp;’ will become ‘$AMP;’ and this will be interpreted wrong in xml