Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

url_title accentuation trouble fix #1466

Closed
larodiel opened this Issue · 2 comments

2 participants

@larodiel

Hello people, I did have some troubles to work with 'url_title' where string have accentuation, after I search a little bit I got fix it.
below two functions to fix the trouble.

if ( ! function_exists('url_title'))
{
function url_title($str, $separator = 'dash', $lowercase = FALSE)
{
//$str = iconv( 'UTF-8', 'ASCII//TRANSLIT', $str );
$str =removeAccentuation($str);
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);
    }

    if ($lowercase === TRUE)
    {
        $str = strtolower($str);
    }

    return trim(stripslashes($str));
}

}
if ( ! function_exists('removeAccentuation')) {
function removeAccentuation ($str, $enc = "UTF-8"){

    $acentos = array(
        'A' => '/À|Á|Â|Ã|Ä|Å/',
        'a' => '/à|á|â|ã|ä|å/',
        'C' => '/Ç/',
        'c' => '/ç/',
        'E' => '/È|É|Ê|Ë/',
        'e' => '/è|é|ê|ë/',
        'I' => '/Ì|Í|Î|Ï/',
        'i' => '/ì|í|î|ï/',
        'N' => '/Ñ/',
        'n' => '/ñ/',
        'O' => '/Ò|Ó|Ô|Õ|Ö/',
        'o' => '/ò|ó|ô|õ|ö/',
        'U' => '/Ù|Ú|Û|Ü/',
        'u' => '/ù|ú|û|ü/',
        'Y' => '/Ý/',
        'y' => '/ý|ÿ/',
        'a.' => '/ª/',
        'o.' => '/º/');

    return preg_replace($acentos,
        array_keys($acentos),
        htmlentities($str,ENT_NOQUOTES, $enc));
}

}

thanks guys

@narfbg
Owner

There's a better way to do this, like this one: #1332, although as you can see - the conclusion is that you should take care of that yourself.

@narfbg narfbg closed this
@narfbg narfbg reopened this
@narfbg
Owner

I'm not sure why I've reopened this right after closing it ...

url_title(convert_accented_characters($string));

Job done.

@narfbg narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.