cocur / slugify

Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.
MIT License
2.88k stars 252 forks source link

Wrong slug generated #200

Open saurabh2k26 opened 6 years ago

saurabh2k26 commented 6 years ago

Input is: Saurabh's Blog Expected output: saurabhs-blog Actual output: saurabh-s-blog

florianeckerstorfer commented 6 years ago

Can you post the code you are using?

tenq commented 4 years ago

I'm with same problem in portuguese.

Input is: Um mês de conteúdo Expected output: um-mes-de-conteudo Actual output: um-me-s-de-conteu-do

Whenever you replace a character, you add (in addition to the replaced character) a separator.

kniziol commented 1 year ago

@saurabh2k26 To be honest, it’s good idea to replace any character different than a-z or 0-9 with separator. In this case apostrophe is also replaced with -. It’s simple and clear.

If we would like to go another way, additional options would be needed to implement:

  1. regex that matches all special characters like apostrophe
  2. separator used to replace these special characters

Optionally we can just clear all the special characters. In this way 2nd new option won’t be necessary, because empty string will be used as separator.

@florianeckerstorfer Any thoughts?

kniziol commented 1 year ago

@tenq Have you tried to use portuguese-brazil or french ruleset?

$slugify->slugify('Um mês de conteúdo', ['ruleset' => 'portuguese-brazil']);
// or
$slugify->slugify('Um mês de conteúdo', ['ruleset' => 'french']);