$string = preg_replace('/[^0-9a-z]/i', '', $string);
For more information on regexp's, you should look at this site. Basically, the pattern says this:
Replace any character that is not 0-9 or a-z, case-insensitive (hence the 'i' modifier at the end), and replace it with an empty string.