Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9118559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:10:57+00:00 2026-06-17T05:10:57+00:00

Previously, I am encountering unterminated string literal strange error in JS: SyntaxError: unterminated string

  • 0

Previously, I am encountering “unterminated string literal strange error” in JS: SyntaxError: unterminated string literal strange error

I kinda fix it using json_encode since newlines are escaped.

Now I am getting these odd results, for example this JS variable (processed with json_encode):

        cacheObj_open.handler='<pre class="brush: html;">"&lt;html&gt;\r\n&lt;body&gt;\r\n&lt;p&gt;Hello world.&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;"</pre>';         

Will output with codes having double quotes around them:

"<html>
<body>
<p>Hello world.</p>
</body>
</html>"

The above code runs without console error. But the one below (also processed with json_encode) throws SyntaxError: missing ; before statement error:

cacheObj_open.handler='<pre class="brush: html;">"\r\n&lt;?php\r\n$stmt = $dbh-&gt;prepare(&quot;SELECT * FROM REGISTRY where name = ?&quot;);\r\nif ($stmt-&gt;execute(array($_GET['name']))) {\r\n  while ($row = $stmt-&gt;fetch()) {\r\n    print_r($row);\r\n  }\r\n}\r\n?&gt;"</pre>';            

What is the best way to avoid any errors when outputting HTML entity source code to a JS variable? I know that json_encode will escape some new lines(this is a good idea) but based on the above example, it still throws an error for some codes. I appreciate any inputs and suggestions.

I have tried adding addslashes on PHP side but it still throws the error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:10:59+00:00Added an answer on June 17, 2026 at 5:10 am

    The error in this case is at execute(array($_GET['name'], the single quotes here close the quotes surrounding the whole string. They should be escaped with a backslash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm encountering a very annoying error using Core Data on Mac OS X 10.5.
Previously, using the ALT+COMMAND+R key combination after highlighting a variable name in a Java
I am encountering a strange issue with the commons-io/java-io. Essentially my file creation is
Previously I had been using this.CommandBindings.Add( new CommandBinding(ApplicationCommands.Copy, this.cmdCopy_Executed, this.cmdCopy_CanExecute)) where cmdCopy_Executed is a
Previously, I generate the programme using code, and I have a super class that
Previously i posted a question in SO , without knowing what caused this error.
Previously, i was using Oracle for my app and all dynamic queries were working
Previously I was not using an interface for my generic repository. When I extracted
Previously, using SVN, I would have a branch that was my development branch, which
Previously I was using CBR_9600 when communicating with 9600 baud devices. But there does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.