コード例 #1
0
ファイル: HuradSanitize.php プロジェクト: hurad/hurad
 public static function title($title, $with = 'default', $when = 'save')
 {
     switch ($with) {
         case 'dash':
             $title = strip_tags($title);
             if (HuradFunctions::isUtf8($title)) {
                 if (function_exists('mb_strtolower')) {
                     $title = mb_strtolower($title, 'utf8');
                 }
                 $title = HuradFunctions::utf8UriEncode($title, 200);
             }
             $title = strtolower($title);
             //Kill entity
             $title = preg_replace('/&.+?;/', ' ', $title);
             $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
             //Replace whitespace with dash
             $title = preg_replace('/\\s+/', '-', $title);
             //Replace multi dash with one dash
             $title = preg_replace('/-+/', '-', $title);
             //Remove dash from start and end of string
             $title = trim($title, '-');
             return HuradHook::apply_filters('sanitize_title_with_dash', $title);
             break;
         case 'default':
         default:
             if ($when == "save") {
                 $safeTitle = filter_var($title, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
             } else {
                 $safeTitle = $title;
             }
             return HuradHook::apply_filters('sanitize_title', $safeTitle, $title, $when);
             break;
     }
 }