1

In CodeIgniter, the url_title function takes a "title" string as input and creates a human-friendly URL string with a "separator" (dash or underscore).

Currently, the function remove single quote. In french, the single quote (apostrophe) is a word separator.

For example : The expected slug for "L'apostrophe" is "l-apostrophe", and not "lapostrophe" as it is currently the output of the url_title function.

I would like to update the following source code (/system/helpers/url_helper.php - line 493):

$trans = array(
    '&.+?;'         => '',
    '[^\w\d _-]'        => '',
    '\s+'           => $separator,
    '('.$q_separator.')+'   => $separator
);

Since but I'm not familiar with RegEx, it would be nice if someone could help me to add single quote in the array $trans in order to convert single quotes into separators.

Fifi
  • 3,360
  • 2
  • 27
  • 53

2 Answers2

1

You might replace [^\w\d _-] with [^\w\d' _-] and \s+ with [\s']+

This pattern [^\w\d _-] is a negated character class which will match a ' and will be replaced by an empty string. If you add ' to the existing character class then is will not be matched and not be replaced.

\s+ matches 1+ whitespace characters and those will be replaced by the separator. You could turn that into a character class [\s']+ and repeat that 1+ times. Then what will be matched here will be replaced by the $separator

Escape the \' in your example as the regex is between single quotes already.

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
1

Modifying the CodeIgniter core is always a problem to ensure upgrade and compatibility with future versions. I would better suggest to update the array of foreign characters for transliteration | conversion used by the Text helper (in /application/config/foreign_chars.php).

Add the following line at the end of the array:

'/\'/' => ' '

This will convert single quotes ('/\'/') to spaces (' ') when calling the convert_accented_characters function.

Mr Robot
  • 1,037
  • 9
  • 17