Using url_title() with Spanish or other strange characters

If you are running your site in Spanish and using url_title to create Permalinks in CodeIgniter then likely you had run in character issues while creating your links.

Martin posted a solution in CodeIgniter’s forum with a workaround for this issue. He proposed


$trans = array(
                    $search                                => $replace,
                    "á"                                    => 'a',
                    "é"                                    => 'e',
                    "í"                                    => 'i',
                    "ó"                                    => 'o',
                    "ú"                                    => 'u',
                    "à"                                    => 'a',
                    "è"                                    => 'e',
                    "ì"                                    => 'i',
                    "ò"                                    => 'o',
                    "ù"                                    => 'u',
                    "ñ"                                    => 'n',
                    "ä"                                    => 'a',
                    "ë"                                    => 'e',
                    "ï"                                    => 'i',
                    "ö"                                    => 'o',
                    "ü"                                    => 'u',
                    "\s+"                                => $replace,
                    "[^a-z0-9".$replace."]"                => '',
                    $replace."+"                        => $replace,
                    $replace."$"                        => '',
                    "^".$replace                        => ''
                   );

My two cents here are the following. You can try to override the URL Helper by extending it in MY_url_helper.php under application/helpers directory.

Related searches:

  • codeigniter url_title
  • url_title codeigniter
  • codeigniter url_title utf8
  • url_title javascript
  • codeIgniter using url_title()
  • codeigniter url_title()
  • codeigniter url_title special characters
  • codeigniter url_title español
  • codeigniter url_title arabic
  • codeigniter title url
  1. Germanz0 says:

    Hi, I was thinking that there is a problem when there are upper cases, becouse the strtolower doesn’t work with special words like the “Ñ”.

  2. Germanz0 says:

    $trans = array(
    $search => $replace,
    “á” => ‘a’,
    “é” => ‘e’,
    “í” => ‘i’,
    “ó” => ‘o’,
    “ú” => ‘u’,
    “à” => ‘a’,
    “è” => ‘e’,
    “ì” => ‘i’,
    “ò” => ‘o’,
    “ù” => ‘u’,
    “ñ” => ‘n’,
    “ä” => ‘a’,
    “ë” => ‘e’,
    “ï” => ‘i’,
    “ö” => ‘o’,
    “ü” => ‘u’,
    “Ñ” => ‘N’,
    “Á” => ‘A’,
    “É” => ‘E’,
    “Í” => ‘I’,
    “Ó” => ‘O’,
    “Ú” => ‘U’,
    “À” => ‘A’,
    “È” => ‘E’,
    “Ì” => ‘I’,
    “Ò” => ‘O’,
    “Ù” => ‘U’,
    “Ä” => ‘A’,
    “Ë” => ‘E’,
    “Ï” => ‘I’,
    “Ö” => ‘O’,
    “Ü” => ‘U’,
    “Ç” => ‘C’,
    “ç” => ‘c’,
    “\s+” => $replace,
    “[^a-z0-9".$replace."]” => ”,
    $replace.”+” => $replace,
    $replace.”$” => ”,
    “^”.$replace => ”
    );

    ————–

    There is my solution, it works for portuguese words too :>

  3. admin says:

    Great. Thanks @Germanzo.

  1. There are no trackbacks for this post yet.

Leave a Reply