// bad characters $cleanchr = preg_replace("/[^ \\\\{}\^`\[\]\|\-\w]/", "", $vbulletin->userinfo['username']); // leading numbers and dashes $cleannum = ereg_replace("^[0-9\-]*[0-9\-]", "", $cleanchr); // convert spaces to underscores $nick = ereg_replace(" ", "_", $cleannum);