slug() public method

Generate a URL friendly "slug".
public slug ( string $separator = '-' ) : string
$separator string
return string
コード例 #1
0
 public function onStart(EnvironmentEvent $event)
 {
     $renderizer = $event->getRenderizer();
     $renderizer->addTwigFilter('slugify', function ($text) {
         $string = new StringWrapper($text);
         return $string->slug();
     });
 }
コード例 #2
0
ファイル: StringWrapperTest.php プロジェクト: rptec/Spress
 public function testSlug()
 {
     $str = new StringWrapper('Welcome to Spress');
     $this->assertEquals('welcome-to-spress', $str->slug());
     $this->assertEquals('bienvenido-a-espana', $str->setString('Bienvenido a España')->slug());
     $this->assertEquals('hello-spress', $str->setString('hello  spress')->slug());
     $this->assertEquals('hello-spress', $str->setString('-hello-spress-')->slug());
     $this->assertEquals('12-cheese', $str->setString('1\\2 cheese')->slug());
     $this->assertEquals('2-step', $str->setString('.,;{}+¨¿?=()/&%$·#@|!ºª2 step     ^[]')->slug());
 }