Function to parse a string for possible combination

    //有可能是: TRI-BACKUP SERIE -> tri-backup-series
    //只能把所有可能找出來
    public static function real_cat($code, $order){
        //explode之後array至少包含1個element
        $chars = explode('-', $code);
        $possible_values = [' ', '-'];

        if(count($chars) == 1){
            $cat = self::where('name', $chars[0])
                ->orderBy('nest_depth', $order)
                ->first();
            return $cat;
        }

        $count = count($chars) - 1;
        $pos = 0;
        for($i = 0; $i < $count; $i++){
            $str_pos = strpos($code, '-', $pos);
            //logg($str_pos);
            foreach ($possible_values as $key => $value) {
                $left = substr($code, 0, $str_pos);
                $right = substr($code, $str_pos + 1);
                $str = $left . $value . $right;
                //echo $str . '<br/>';

                $cat = self::where('name', $str)
                    ->orderBy('nest_depth', $order)
                    ->first();
                if($cat != false){
                    return $cat;
                }
            }

            $pos = $str_pos + 1;
        }
        //logg('done');

        return false;
    }