0

I am using the Codeigniter PHP framework, and when I save some text to the database using their native method db->query the character & is becoming & when I reload the page and it is inserted in the textarea element

what is going on? when I reload, In PHP I am using db->query to select rows in the database and json_encode to echo the JSON string to the client. In the client side I am using JSON.parse

additional info: when I access phpmyadmin to see the content of the table, I can see the & char there

@edit

i'm not echoing the JSON in this case. it's not an AJAX situation. i am inserting the encoded JSON to an HTML element, getting the innerHTML property and parsing when the document is loaded

it seems that many browsers have an inbuilt functionality that encodes many chars like <, & etc

please, refere to this Answer to "Convert special characters to HTML in Javascript"

Now what I need is a fix to this. What to do with encoded chars by browsers when we use the innerHTML property in Javascript

Community
  • 1
  • 1
Victor Ferreira
  • 6,151
  • 13
  • 64
  • 120
  • 2
    what code you using for generate HTML (native PHP or some HTML helper)? Probably HTML helper escape it. – stepozer Jan 16 '15 at 18:30
  • hey there. i was mistaken, i am not echoing it. I am actually inserting the json in a hidden HTML element. it seems that the browser has an inbuilt functionality that will escape the chars. weird, now I want to know how to deal with it i'm not using any helper. i am getting the innerHTML of that element, parsing it with JSON.parse and assigning to `value` of the textarea – Victor Ferreira Jan 16 '15 at 21:18
  • probably it answer to your question: http://stackoverflow.com/questions/16252931/getting-inner-html-without-escaping-or-decoding-anything-with-jquery – stepozer Jan 17 '15 at 07:47

0 Answers0