August 29, 2012

SyntaxError: unterminated string literal – PHP/XHTML String

SyntaxError: unterminated string literal – PHP/XHTML String

<?php $string = addslashes(preg_replace("/[\r\n]+/",' ',(preg_replace('/\s\s+/', ' ', include("xhtml_page.php")))); ?>

Note:

New lines in string will be removed and the string will be a valid string instead of unterminated string in javascript.

<script type="text/javascript" language="javascript">var js_str = '<?php echo $string; ?>';</script>

Last updated: March 19, 2014
Did it helped? One thought on “SyntaxError: unterminated string literal – PHP/XHTML String
  1. Babar

    Great! it worked fine. Thanks

Comments are closed.