yaroslavbr
2/26/2014 - 3:09 PM

Something like parser for condion on value existing . With smary-like syntax :{if condition_tag} Some text will be seen if condition_tag is

Something like parser for condion on value existing . With smary-like syntax :{if condition_tag} Some text will be seen if condition_tag is true{/if} Supports nested conditions, something like that can be used: {if condition} Condition {if nested_condition} Nested Condition{/if}{/if}

public function applyPatterns($meta, $keys) {

        //Prepare keys
        foreach ($keys as $k => $v) {
            $search[] = $k;
            $replace[] = $v;
        }

        foreach ($meta as $key => &$val) {

            do {
                $matches = array();
                preg_match('/\{if (.*?)\}(.*?)\{\/if\}/', $val, $matches);

                if (isset($matches[1])) {

                    $temp_val = '';
                    $condition = $matches[0];
                    $temp_key = $matches[1];
                    if (isset($keys['{' . $temp_key . '}']) && $keys['{' . $temp_key . '}'] && isset($matches[2])) {
                        $temp_val = $matches[2];
                    }
                    $val = str_replace($condition, $temp_val, $val);
                }
            } while (isset($matches[1]));



            if (isset($search))
                $val = str_replace($search, $replace, $val);
            // die($val);
        }

        return $meta;
    }