gergelypolonkai-web-symfony2/src/GergelyPolonkai/FrontBundle/Service/Slugifier.php
Gergely Polonkai (W00d5t0ck) 5bcd9f079b Added basic blog functionality
Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
2012-09-04 13:09:32 +02:00

44 lines
1.3 KiB
PHP

<?php
namespace GergelyPolonkai\FrontBundle\Service;
use JMS\DiExtraBundle\Annotation as DI;
/**
* Description of Slugifier
*
* @author polonkai.gergely
*
* @DI\Service("slugifier")
*/
class Slugifier
{
public function slugify($string)
{
$string = strtolower(
preg_replace(
'/^-+/',
'',
preg_replace(
'/-+$/',
'',
preg_replace(
'/[^a-z]+/i',
'-',
preg_replace(
'/([a-z])[":\']/i',
'\1',
iconv(
'UTF-8',
'ASCII//TRANSLIT',
$string
)
)
)
)
)
);
return $string;
}
}