I've just built a web software app implemented mainly in Javascript, which involves a lot of user-entered text which must be stored and retrieved from a server-based database. So user-entered text is handled initially by Javascript, which generates HTTP POST calls to pass the text to a PHP function, which in turn must generate MySQL commands to store it in the database. The whole process has to work in reverse to get text from MySQL back through PHP which puts the text into a JSON string for return to the Javascript program.
Well, since the user can enter any text whatsoever, including any punctuation, symbols pasted in from a word processor, extended ASCII, foreign alphabets and symbols in Unicode, etc., the problem becomes how to encode it in such a way that nothing in the text will have any syntactic meaning in Javascript, PHP, or MySQL. That turned out to be a hair-puller for me. I tried all sorts of built-in Javascript and PHP encoding functions, as well as various ones I found on the web, but could not find anything existent that wouldn't stumble over SOMEthing.
So I invented my own text-encoding technique. My requirements:
* Encoded text must consist of nothing but the ASCII alphabetic letters and digits 0-9, plus a single "escape" character.
* Must be able to faithfully encode ANY text that's valid in Unicode and then decode it to be identical to the original.
* The application must be able to designate ANY character code as the escape (except letters and digits), so as to avoid collisions with whatever languages or systems it needs to be compatible with.
* The encoded text should be basically readable by a human (assuming it's written primarily using the ASCII alphabetic characters).
* It should be possible for any program to decode the text without having prior knowledge of what character was used as the escape during encoding.
Maybe there's something already out there that does all of this. If so, I'd like to know about it, even though it'll mean I've just re-invented the wheel. If not, and if folks are interested, I'll be happy to share what I've come up with.
Well, since the user can enter any text whatsoever, including any punctuation, symbols pasted in from a word processor, extended ASCII, foreign alphabets and symbols in Unicode, etc., the problem becomes how to encode it in such a way that nothing in the text will have any syntactic meaning in Javascript, PHP, or MySQL. That turned out to be a hair-puller for me. I tried all sorts of built-in Javascript and PHP encoding functions, as well as various ones I found on the web, but could not find anything existent that wouldn't stumble over SOMEthing.
So I invented my own text-encoding technique. My requirements:
* Encoded text must consist of nothing but the ASCII alphabetic letters and digits 0-9, plus a single "escape" character.
* Must be able to faithfully encode ANY text that's valid in Unicode and then decode it to be identical to the original.
* The application must be able to designate ANY character code as the escape (except letters and digits), so as to avoid collisions with whatever languages or systems it needs to be compatible with.
* The encoded text should be basically readable by a human (assuming it's written primarily using the ASCII alphabetic characters).
* It should be possible for any program to decode the text without having prior knowledge of what character was used as the escape during encoding.
Maybe there's something already out there that does all of this. If so, I'd like to know about it, even though it'll mean I've just re-invented the wheel. If not, and if folks are interested, I'll be happy to share what I've come up with.