i need to pass an html template to a javascript variable in php
i tried differents things like json_encode(), str_replace() addcslashes() but javascript always throw an error of unexpected character
<?php
$html = file_get_contents('template.html');
function escapeJavaScriptText($string)
{
return str_replace("\n", '\n', str_replace('"', '\"', addcslashes(str_replace("\r", '', (string)$string), "\0..\37'\\")));
}
?>
<script> var template = "<?php echo escapeJavaScriptText($html) ?>"</script>