コード例 #1
0
ファイル: Slug.php プロジェクト: oesteve/grupeta
 public static function makeSlugs($string, $maxlen = 0)
 {
     $newStringTab = array();
     $string = strtolower(Slug::noDiacritics($string));
     if (function_exists('str_split')) {
         $stringTab = str_split($string);
     } else {
         $stringTab = my_str_split($string);
     }
     $numbers = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-");
     //$numbers=array("0","1","2","3","4","5","6","7","8","9");
     foreach ($stringTab as $letter) {
         if (in_array($letter, range("a", "z")) || in_array($letter, $numbers)) {
             $newStringTab[] = $letter;
             //print($letter);
         } elseif ($letter == " ") {
             $newStringTab[] = "-";
         }
     }
     if (count($newStringTab)) {
         $newString = implode($newStringTab);
         if ($maxlen > 0) {
             $newString = substr($newString, 0, $maxlen);
         }
         $newString = Slug::removeDuplicates('--', '-', $newString);
     } else {
         $newString = '';
     }
     return $newString;
 }