you could do this with regular expression functions like ereg_replace() or preg_replace().
try something like
$output_string = ereg_replace("[[:alnum:]]", "", $input_string)
This should insert a null value (nothing) in place of any non-alphanumerics. I think it might also strip out spaces.