0

I'm trying to add HTML to a page via AJAX. I have the HTML saved in a database, but when I retrieve it from the database and try to append on HTML with JQuery it always breaks the sting whenever the HTML contains a single quotation mark.

It worked when I used HTML special chars (Except obviously wasn't html), however when I tried to convert it back into HTML I got the same issue.

I need to do this to convert the PHP to Javascript, and used a single quote as the HTML uses double quotes for it's tags.

var val = '<?php echo $val ?>'

So any single quote in the HTML is going to break the string. I've tried a few things and tried to search for an answer and ended up giving up for a week :/

ElCodes
  • 21
  • 6

1 Answers1

0

I do not know if I can understand it correctly. But try the following:

var val = '<?php echo nl2br($val); ?>'

Or

var val = '<?php echo htmlentities($val); ?>'

Good Luck.

  • Thanks for answering, but I found the solution here. https://stackoverflow.com/questions/7394748/whats-the-right-way-to-decode-a-string-that-has-special-html-entities-in-it?lq=1 – ElCodes Jun 19 '19 at 23:49