Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url_title accentuation trouble fix #1467

Closed
larodiel opened this issue Jun 13, 2012 · 1 comment
Closed

url_title accentuation trouble fix #1467

larodiel opened this issue Jun 13, 2012 · 1 comment

Comments

@larodiel
Copy link

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
Copy link
Contributor

narfbg commented Jun 13, 2012

Duplicate of #1466.

@narfbg narfbg closed this as completed Jun 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants