Skip to content

Commit 161b508

Browse files
committed
Made the slugger compatible with every language
1 parent f3d2d9a commit 161b508

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/AppBundle/Utils/Slugger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class Slugger
2727
*/
2828
public function slugify($string)
2929
{
30-
return trim(preg_replace('/[^a-z0-9]+/', '-', strtolower(strip_tags($string))), '-');
30+
return preg_replace('/\s+/', '-', mb_strtolower(trim(strip_tags($string)), 'UTF-8'));
3131
}
3232
}

tests/AppBundle/Utils/SluggerTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ public function testSlugify($string, $slug)
3838

3939
public function getSlugs()
4040
{
41-
yield ['Lorem Ipsum' , 'lorem-ipsum'];
42-
yield [' Lorem Ipsum ' , 'lorem-ipsum'];
43-
yield [' lOrEm iPsUm ' , 'lorem-ipsum'];
44-
yield ['!Lorem Ipsum!' , 'lorem-ipsum'];
45-
yield ['lorem-ipsum' , 'lorem-ipsum'];
41+
yield ['Lorem Ipsum', 'lorem-ipsum'];
42+
yield [' Lorem Ipsum ', 'lorem-ipsum'];
43+
yield [' lOrEm iPsUm ', 'lorem-ipsum'];
44+
yield ['!Lorem Ipsum!', '!lorem-ipsum!'];
45+
yield ['lorem-ipsum', 'lorem-ipsum'];
46+
yield ['lorem 日本語 ipsum', 'lorem-日本語-ipsum'];
47+
yield ['lorem русский язык ipsum', 'lorem-русский-язык-ipsum'];
48+
yield ['lorem العَرَبِيَّة‎‎ ipsum', 'lorem-العَرَبِيَّة‎‎-ipsum'];
4649
}
4750
}

0 commit comments

Comments
 (0)