2012-07-17 19:37:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\FrontBundle\Extensions;
|
|
|
|
|
|
|
|
class Slugifier
|
|
|
|
{
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* Slugify string
|
|
|
|
*
|
2012-08-17 14:18:43 +00:00
|
|
|
* @param string $text
|
2012-08-16 13:52:41 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function slugify($text)
|
|
|
|
{
|
|
|
|
$text = preg_replace(
|
|
|
|
'~[^-\w]+~',
|
|
|
|
'',
|
|
|
|
str_replace(
|
|
|
|
array('"', "'", ':'),
|
|
|
|
'',
|
|
|
|
strtolower(
|
|
|
|
iconv(
|
|
|
|
'utf-8',
|
|
|
|
'us-ascii//TRANSLIT',
|
|
|
|
trim(
|
|
|
|
preg_replace(
|
|
|
|
'~[^\\pL\d]+~u',
|
|
|
|
'-',
|
|
|
|
$text
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2012-07-17 19:37:54 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
if (empty($text)) {
|
|
|
|
$text = 'n-a';
|
|
|
|
}
|
2012-07-17 19:37:54 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $text;
|
|
|
|
}
|
2012-07-17 19:37:54 +00:00
|
|
|
}
|