- trim: documentation ( source)
- preg_replace: documentation ( source)
<?php
$str = 'test"';
$str = trim($str);
$str = preg_replace("#[&].{2,7}[;]#sim", " ", $str);
$str = preg_replace("#[()A°^!\"A§\$%&/{(\[)\]=}?AŽ`,;.:\-_\#'~+*]#", " ", $str);
$str = preg_replace("#\s+#sim", " ", $str);
echo $str;
?>