/lib/Slugify.class.php
Использование
class SlugifyClass { static function Slugify($title) { $gost = array( "Є"=>"EH","І"=>"I","і"=>"i","№"=>"#","є"=>"eh", "А"=>"A","Б"=>"B","В"=>"V","Г"=>"G","Д"=>"D", "Е"=>"E","Ё"=>"JO","Ж"=>"ZH", "З"=>"Z","И"=>"I","Й"=>"JJ","К"=>"K","Л"=>"L", "М"=>"M","Н"=>"N","О"=>"O","П"=>"P","Р"=>"R", "С"=>"S","Т"=>"T","У"=>"U","Ф"=>"F","Х"=>"KH", "Ц"=>"C","Ч"=>"CH","Ш"=>"SH","Щ"=>"SHH","Ъ"=>"'", "Ы"=>"Y","Ь"=>"","Э"=>"EH","Ю"=>"YU","Я"=>"YA", "а"=>"a","б"=>"b","в"=>"v","г"=>"g","д"=>"d", "е"=>"e","ё"=>"jo","ж"=>"zh", "з"=>"z","и"=>"i","й"=>"jj","к"=>"k","л"=>"l", "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r", "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"kh", "ц"=>"c","ч"=>"ch","ш"=>"sh","щ"=>"shh","ъ"=>"", "ы"=>"y","ь"=>"","э"=>"eh","ю"=>"yu","я"=>"ya","«"=>"","»"=>"","—"=>"-"," "=>"-" ); $iso = array( "Є"=>"YE","І"=>"I","Ѓ"=>"G","і"=>"i","№"=>"#","є"=>"ye","ѓ"=>"g", "А"=>"A","Б"=>"B","В"=>"V","Г"=>"G","Д"=>"D", "Е"=>"E","Ё"=>"YO","Ж"=>"ZH", "З"=>"Z","И"=>"I","Й"=>"J","К"=>"K","Л"=>"L", "М"=>"M","Н"=>"N","О"=>"O","П"=>"P","Р"=>"R", "С"=>"S","Т"=>"T","У"=>"U","Ф"=>"F","Х"=>"X", "Ц"=>"C","Ч"=>"CH","Ш"=>"SH","Щ"=>"SHH","Ъ"=>"'", "Ы"=>"Y","Ь"=>"","Э"=>"E","Ю"=>"YU","Я"=>"YA", "а"=>"a","б"=>"b","в"=>"v","г"=>"g","д"=>"d", "е"=>"e","ё"=>"yo","ж"=>"zh", "з"=>"z","и"=>"i","й"=>"j","к"=>"k","л"=>"l", "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r", "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"x", "ц"=>"c","ч"=>"ch","ш"=>"sh","щ"=>"shh","ъ"=>"", "ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya","«"=>"","»"=>"","—"=>"-"," "=>"-" ); $rtl_standard = sfConfig::get('rtl_standard', 'gost') ; //to lower case $title = mb_strtolower($title, 'UTF-8'); switch ($rtl_standard) { case 'off': return $title; case 'gost': $out = trim(strtr($title, $gost), '-'); default: $out = trim(strtr($title, $iso), '-'); } // clean slug $out = preg_replace('/[^a-z0-9\-]+/i', '', $out); return $out; } }
Использование
Post: actAs: Timestampable: ~ Taggable: ~ Sluggable: unique: true fields: [title] canUpdate: true builder: [SlugifyClass, Slugify]
5 комментариев:
Я бы еще убрал спецсимволы, вообщем-то все кроме a-z0-9_- .
Кусок схемы - это для doctrine?
Да, конечно схема для Доктрины.
А насчет набора символов, тут можно править как угодно ;)
Я этот набор выдернул из Вордпресса.
Может вы мне поможите? Создал схму на доктрине, пытаюсь заполнить из fixtures (symfony 1.2.9), пишет:
Notice: iconv_strlen(): Detected an illegal character in input string...
SQLSTATE[HY000]: General error: 1366 Incorrect string value: ...
Причем для тех колонок где на русском данные. В базе кодировка cp1251.
у меня тоже была такая ошибка когда хотел добавить slug ... поэтому пока отложил ... но решение хотелсь бы видеть
небольшая поправка.
$name = mb_strtolower($name, 'UTF-8');
Отправить комментарий