PHP Regex Snippet: Convert a Title to a Code

This will take out any non-alphanumeric characters and replace them with an underscore

    protected function convertTitleToCode($title)
    {
        return preg_replace("/[^\w]/i", "_", trim(strtolower($title)));
    }