Welcome Guest, Not a member yet? Register   Sign In
Is there a standard way to handle diacritics in URLs for CI?
#1

[eluser]Matthew Pennell[/eluser]
Hello - I've not worked with CI for a couple of years so I may have missed a development in this area.

Is there a standard way to handle creating url_title type strings from strings that contain diacritics? If I wanted to map Résumé to /about-me/resume/ - has anyone created a way to do it?
#2

[eluser]jáquer[/eluser]
Maybe use something like this? Add this to an "unaccent" helper:

Code:
function unaccent($text) {
  static $search, $replace;
  if (!$search) {
    $search = $replace = array();
    // Get the HTML entities table into an array
    $trans = get_html_translation_table(HTML_ENTITIES);
    // Go through the entity mappings one-by-one
    foreach ($trans as $literal => $entity) {
      // Make sure we don't process any other characters
      // such as fractions, quotes etc:
      if (ord($literal) >= 192) {
        // Get the accented form of the letter
        $search[] = utf8_encode($literal);
        // Get e.g. 'E' from the string 'É'
        $replace[] = $entity[1];
      }
    }
  }
  return str_replace($search, $replace, $text);
}

And then:

Code:
$this->load->helper('url');
$this->load->helper('unaccent');

$title = unaccent($title);
$title = url_title($title, 'dash', TRUE);

Code for the unaccent function found a hasty Google search, which lead me here. There might be better implementations of it.
#3

[eluser]Matthew Pennell[/eluser]
Thanks, that looks like it might be useful. Smile




Theme © iAndrew 2016 - Forum software by © MyBB