/** * Return a "URL friendly" version in lowercase. * * Define the words separator with the configuration * option <code>slug-separator</code>. Default to <code>-</code>. * * @param $value string Value to convert * @return string The slugify version. */ public static function slugify($value) { $separator = Pluf::f('slug-separator', '-'); $value = Pluf_Text_UTF8::romanize(Pluf_Text_UTF8::deaccent($value)); $value = preg_replace('#[^' . $separator . '\\w]#u', $separator, mb_strtolower($value, Pluf::f('encoding', 'UTF-8'))); // remove redundant $value = preg_replace('#' . $separator . '{2,}#u', $separator, trim($value, $separator)); return $value; }
/** * Convert encoding to UTF8. * * If an array is given, the encoding is detected only on the * first value and then used to convert all the strings. * * @param mixed String or array of string to be converted * @param bool Returns the encoding together with the converted text (false) * @return mixed String or array of string or array of res + encoding */ public static function toUTF8($text, $get_encoding = False) { $enc = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS'; $ref = $text; if (is_array($text)) { $ref = $text[0]; } if (Pluf_Text_UTF8::check($ref)) { return !$get_encoding ? $text : array($text, 'UTF-8'); } $encoding = mb_detect_encoding($ref, $enc, true); if ($encoding == false) { $encoding = Pluf_Text_UTF8::detect_cyr_charset($ref); } if (is_array($text)) { foreach ($text as $t) { $res[] = mb_convert_encoding($t, 'UTF-8', $encoding); } return !$get_encoding ? $res : array($res, $encoding); } else { $res = mb_convert_encoding($text, 'UTF-8', $encoding); return !$get_encoding ? $res : array($res, $encoding); } }