- str_replace: documentation ( source)
- preg_replace: documentation ( source)
<?php
function clean($string) {
$string = str_replace(' ', '', $string);
return preg_replace('/[^A-Za-z0-9\-]/', '', $string);
}
$string = 'Lee%-&*d#';
echo clean($string);
echo "\n";
echo $string;