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