$char) { $translation[$char] = $target[$key]; } // Convert weird characters using the list, replace the rest with underscores. $name = strtr($name, $translation); $name = preg_replace('/[^a-zA-Z0-9,._\+\()\-]/', '_', $name); // Return with limited length return substr($name, 0, $maxlen); }