Skip to content

Commit 5c82409

Browse files
author
Sebastian Blum
committed
Optimized slugger: trimming dash at the beginning & end and removed double dashes
1 parent 8cf500c commit 5c82409

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/AppBundle/Tests/Utils/SluggerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function getSlugs()
4242
return array(
4343
array('Lorem Ipsum' , 'lorem-ipsum'),
4444
array(' Lorem Ipsum ' , 'lorem-ipsum'),
45-
array(' lOrEm iPsUm ' , 'lorem--ipsum'),
45+
array(' lOrEm iPsUm ' , 'lorem-ipsum'),
46+
array('!Lorem Ipsum!' , 'lorem-ipsum'),
47+
array('lorem-ipsum' , 'lorem-ipsum'),
4648
);
4749
}
4850
}

src/AppBundle/Utils/Slugger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ class Slugger
2222
{
2323
public function slugify($string)
2424
{
25-
return preg_replace('/[^a-z0-9]/', '-', strtolower(trim(strip_tags($string))));
25+
return trim(preg_replace('/[^a-z0-9]+/', '-', strtolower(trim(strip_tags($string)))), '-');
2626
}
2727
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy