Regex
/* Leave only numbers and letters */ $clean_code = preg_replace('/[^\w]/', '', $string); /* More controll */ $clean_code = preg_replace('/[^a-zA-Z0-9]/', '', $string);