Skip to content

Commit

Permalink
Fix the ordering of stripping and transliteration
Browse files Browse the repository at this point in the history
This was kind of a silly way to do this. First stripping everything that is not default, and then using iconv transliteration. At that point there would be no special chars left. This explains why i always lose my French éàç characters in the slug :)

Fixes #8
  • Loading branch information
Roderik van der Veer committed May 20, 2014
1 parent a6ce2f8 commit 41d37fd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Helper/Slugifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class Slugifier
*/
public static function slugify($text, $default = 'n-a')
{

$text = preg_replace('#[^\\pL\d\/]+#u', '-', $text); // replace non letter or digits by -
$text = trim($text, '-'); //trim

// transliterate
if (function_exists('iconv')) {
$previouslocale = setlocale(LC_CTYPE, 0);
Expand All @@ -29,6 +25,9 @@ public static function slugify($text, $default = 'n-a')
setlocale(LC_CTYPE, $previouslocale);
}

$text = preg_replace('#[^\\pL\d\/]+#u', '-', $text); // replace non letter or digits by -
$text = trim($text, '-'); //trim

$text = strtolower($text); // lowercase
$text = preg_replace('#[^-\w\/]+#', '', $text); // remove unwanted characters

Expand Down

0 comments on commit 41d37fd

Please sign in to comment.