{*
 Шаблон вычисления "Текст: Удалить HTML-форматирование"
*}

if (!function_exists('cut_css')) {
    function cut_css($txt) {
        $block = 0;
        $arr = explode("\n", $txt);
        foreach ($arr as $k => $str) {
            $str = trim($str);
            if (substr($str, -1) == '{ldelim}') {
                $block++;
            }
            if (substr($str, 0, 1) == '{rdelim}' ) {
                $block--;
            }
            if ($block) {
                unset($arr[$k]);
                for ($i = 1; ; $i++) {
                    if (!isset($arr[$k - $i])) {
                        break;
                    }
                    if (substr(trim($arr[$k - $i]), -1) == ',') {
                        unset($arr[$k - $i]);
                    }
                }
            } elseif (substr($str, -1) == '{ldelim}' || substr($str, -1) == '{rdelim}' ) {
                unset($arr[$k]);
            } elseif (substr($str, 0, 1) == '[' && substr($str, -1) == ',') {
                unset($arr[$k]);
            } elseif (substr($str, 0, 2) == '/*' && substr($str, -2) == '*/') {
                unset($arr[$k]);
            }
        }
        return implode("\n", $arr);
    }
}

$line['{$res_field}'] = cut_css(strip_tags(preg_replace('#<style>(.|\n(?!\s+<))*?</style>#', '', preg_replace('#<script>(.|\n(?!\s+<))*?</script>#', '', trim($line['{$sel_field}'])))));