将多行PHP字符串插入Javascript变量

My question
My question is about correctly parsing HTML from php into a variable inside of a javascript object (which in this case is ace-editor's value variable)

My problem
I have got a textarea for HTML and CSS, the HTML gets retrieved from the database and needs to be inserted into a field of croppie, i am currently using PHP's json_encode functionality to put it inside of the variable, but it seems to still escape from the value.

My code

<?php

        $css = ($modify) ? trim($template->style()) : "";
        $html = ($modify) ? trim( $template->html() ) : "";

        $html = json_encode($html);
        $css = json_encode($css);


    ?>
YUI().use(
        'aui-ace-editor',
        function(Y) {
            var editorhtml = new Y.AceEditor({
                boundingBox: '#editor-html',
                height: '400',
                mode: 'html',
                value: '<?php echo substr( $html, 1, -1 ); ?>',
                width: '100%',
                showPrintMargin: false
            }).render();

            var editorcss = new Y.AceEditor({
                boundingBox: '#editor-css',
                height: '400',
                mode: 'css',
                value: '<?php echo substr( $css, 1, -1 ); ?>',
                width: '100%',
                showPrintMargin: false
            }).render();
        }
    );

What happens
When i use this, and open up a specific template which can be managed, i will not be able to see the textarea's (because the ace editor could not be loaded), i get random errors relating to line 666 which is the exact line the HTML gets stored in. I did sanitize the outputs in json_encode correctly.. right?

Screenshot of html inserted into page
in this screenshot, you can see the HTML/css which gets inserted. But the problem occurs on line 666 which the HTML is located at.

Click here if the screenshot isn't readable for you

So my question is..
Why exactly does it not parse the HTML into the object correctly? Am i not sanitizing it correctly or am i missing something?

Your issue is because your $html string contains single quotes, try escaping them or using double quotes

You are breaking the output of json_encode by changing double quotes it creates to single quotes.

It's better to call json_encode directly when adding value to the script tag:

value: <?php echo json_encode($html); ?>,