I would hardly consider myself an expert, but I think this is how you do it:
<?php
if (!eregi("[[:alnum:]]", $variable) {
$variable = ereg_replace("[[[:alnum:]]]", "", $variable);
} else {
do whatever you want to here
}
?>
Like I said, i'm not really an expert on regular expressions yet and this code stands a very good chance of producing errors.