- trim: documentation ( source)
- preg_replace: documentation ( source)
<?php
$string = "ABCDE ";
echo trim($string)."\n";
echo preg_replace('/\s+/', '', $string)."\n";
echo preg_replace('/\s\s+/', '', $string)."\n";
echo trim(preg_replace('/[\s\t\n\r\s]+/', '', $string))."\n";
echo preg_replace('/~\x{00a0}~siu/', '', $string);