I have this strange unterminated string literal error in JavaScript. When I output only a single word like "php" (in the cache_open.handler variable). There is no error. This is the script and below works fine:
<script>
var cache_open = {};
var cache_name_open={};
var handler='open';
cache_open.handler='<pre class="brush: html;">php</pre>';
cache_name_open.handler='PHP prepared statement';
</script>
However when I output a code (html entity outputted source code) to the culprit variable cache_open.handler, it returns unterminated string literal error in the console.
This is the sample output where it returns an error:
<script>
var cache_open = {};
var cache_name_open={};
var handler='open';
cacheObj_open.handler='<pre class="brush: html;">
<?php
$stmt = $dbh->prepare("SELECT * FROM REGISTRY where name = ?");
if ($stmt->execute(array($_GET['name']))) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
?></pre>';
cache_name_open.handler='PHP prepared statement';
</script>
At first I thought it was just the complexity of the code returned (for example containing quotes, etc.). But even a simple HTML code also returns an error:
<script>
var cache_open = {};
var cache_name_open={};
var handler='open';
cacheObj_open.handler='<pre class="brush: html;"><html>
<body>
<p>Hello world.</p>
</body>
</html></pre>';
cache_name_open.handler='PHP prepared statement';
</script>
Any ideas what is causing the error? Any suggestions for modifications is highly appreciated thanks!