Welcome Guest, Not a member yet? Register   Sign In
Disallowing periods etc in url_title()
#1

[eluser]rt30000[/eluser]
How should I go about removing periods (and preferably empty trailing spaces as well) with the CI url_title() helper function? Below is the CI helper function code. Also, shouldn't I create my own helper rather than modify the system one? I have seen references to this, but have yet to extend or modify core files. I will have to look up this, if so. Thanks!!

Code:
// ------------------------------------------------------------------------

/**
* Create URL Title
*
* Takes a "title" string as input and creates a
* human-friendly URL string with either a dash
* or an underscore as the word separator.
*
* @access    public
* @param    string    the string
* @param    string    the separator: dash, or underscore
* @return    string
*/
if ( ! function_exists('url_title'))
{
    function url_title($str, $separator = 'dash')
    {
        if ($separator == 'dash')
        {
            $search        = '_';
            $replace    = '-';
        }
        else
        {
            $search        = '-';
            $replace    = '_';
        }

        $trans = array(
                        '&\#\d+?;'                => '',
                        '&\S+?;'                => '',
                        '\s+'                    => $replace,
                        '[^a-z0-9\-\._]'        => '',
                        $replace.'+'            => $replace,
                        $replace.'$'            => $replace,
                        '^'.$replace            => $replace
                      );

        $str = strip_tags($str);

        foreach ($trans as $key => $val)
        {
            $str = preg_replace("#".$key."#i", $val, $str);
        }

        return trim(stripslashes($str));
    }
}

// ------------------------------------------------------------------------




Theme © iAndrew 2016 - Forum software by © MyBB