src/Leevel/View/Compiler.php
protected function escapeCharacter(string $txt, bool $esc = true): string
    {
        if ('""' === $txt) {
            $txt = '';
        }

        if ($esc) {
            // 转义
            $txt = str_replace([
                '\\\\',
                "\\'",
                '\\"',
                '\\$',
                '\\.',
            ], [
                '\\',
                '~~{#!`!#}~~',
                '~~{#!``!#}~~',
                '~~{#!S!#}~~',
                '~~{#!dot!#}~~',
            ], $txt);
        } else {
            // 还原
            $txt = str_replace([
                '~~{#!`!#}~~',
                '~~{#!``!#}~~',
                '~~{#!S!#}~~',
                '~~{#!dot!#}~~',
            ], [
                "'",
                '"',
                '$',
                '.',
            ], $txt);
        }

        return $txt;
    }
protected function escapeCharacter(string $txt, bool $esc = true): string
    {
        if ('""' === $txt) {
            $txt = '';
        }

        if ($esc) {
            // 转义
            $txt = str_replace([
                '\\\\',
                "\\'",
                '\\"',
                '\\$',
                '\\.',
            ], [
                '\\',
                '~~{#!`!#}~~',
                '~~{#!``!#}~~',
                '~~{#!S!#}~~',
                '~~{#!dot!#}~~',
            ], $txt);
        } else {
            // 还原
            $txt = str_replace([
                '~~{#!`!#}~~',
                '~~{#!``!#}~~',
                '~~{#!S!#}~~',
                '~~{#!dot!#}~~',
            ], [
                "'",
                '"',
                '$',
                '.',
            ], $txt);
        }

        return $txt;
    }
正则属性转义.

@param string $txt
@param bool   $esc

@return string