Trying to replace string with "\" (backslash)

Just use URL escaping (code I posted above) and then you do not have to worry about user entry at all. 

Simple :slight_smile:

Why did you add “-” next to the “###” in my example i didn’t put it for a reason it will not work with gsub, but this is the worst implementation ever. I just gave you an example how to resolve your problem changing 1 char.if you copy paste my example it will work.

you should also send data in json with POST method. it’s pretty easy to use that data in php on the server side.

never had a problem with that.

Unfortunately, the socket.url.escape did not work with the national characters like æøå/äöü so I have to use the string = mime.b64(string) that XedurR suggested. But I also had to avoid a lot of characters that can be entered with the English/Norwegian and German keyboard that we at the moment will support.

I am using MySQL Database and PHP 7.2.7 and I have problems saving e.g. the the backslash (), percent (%) and the combination ("/>")

On the Server I am therefore looping through all the request variable from GET or from POST and decode the values ($value = base64_decode($value),  convert some values back to what they should be before the data is saved.

Here is the code that I use to remove/replace characters that cause problems on the Server:

removeCharsWithError = function(newChar) local mime = require("mime") local replaceChar = "" local theAscii = string.byte(newChar) or -1 local theb64 = mime.b64(newChar) or -1 if theAscii == 92 then -- backslash "\" replaceChar = "/" elseif newChar =="°" then -- degree -- works on Mac Simulator replaceChar = "\*" elseif theAscii == 203 then -- degree -- Ascii value = 194 on Mac, 203 on iPad replaceChar = "\*" elseif theb64 == "y5o=" then -- degree -- theb64 value = "wrA=" on Mac, "y5o=" on iPad replaceChar = "\*" elseif newChar =="•" then replaceChar = "-" elseif newChar =="±" then -- works on Mac Simulator replaceChar = "+/-" elseif theb64 == "4omg" then --on iPad replaceChar = "+/-" end -- variations of letters --on iPad -- A if theb64 == "xIA=" then -- Overline replaceChar = "A" elseif theb64 == "xIE=" then replaceChar = "a" -- E elseif theb64 == "xJY=" then -- One dot replaceChar = "E" elseif theb64 == "xJc=" then replaceChar = "e" elseif theb64 == "w4s=" then -- Two dots - German keyboard replaceChar = "E" elseif theb64 == "w6s=" then replaceChar = "e" elseif theb64 == "xJg=" then -- Polish E replaceChar = "E" elseif theb64 == "xJk=" then replaceChar = "e" elseif theb64 == "xJI=" then -- Overline replaceChar = "E" elseif theb64 == "xJM=" then replaceChar = "e" -- U elseif theb64 == "xao=" then -- Overline replaceChar = "U" elseif theb64 == "xas=" then replaceChar = "u" -- I elseif theb64 == "xKo=" then -- Overline replaceChar = "I" elseif theb64 == "xKs=" then replaceChar = "i" elseif theb64 == "xK4=" then -- La cédille - English keyboard replaceChar = "I" elseif theb64 == "xK8=" then replaceChar = "i" -- O elseif theb64 == "xYw=" then -- Overline replaceChar = "O" elseif theb64 == "xY0=" then replaceChar = "o" -- S elseif theb64 == "xZo=" then -- accent aigu replaceChar = "S" elseif theb64 == "xZs=" then replaceChar = "s" -- C elseif theb64 == "xIw=" then -- c with caron replaceChar = "C" elseif theb64 == "xI0=" then replaceChar = "c" elseif theb64 == "xIY=" then -- accent aigu replaceChar = "C" elseif theb64 == "xIc=" then replaceChar = "c" elseif theb64 == "w4c=" then -- cedilla replaceChar = "C" elseif theb64 == "w6c=" then replaceChar = "c" -- N elseif theb64 == "xYM=" then -- accent aigu -- German keyboard replaceChar = "N" elseif theb64 == "xYQ=" then replaceChar = "n" -- Z elseif theb64 == "xbk=" then -- accent aigu -- English keyboard replaceChar = "Z" elseif theb64 == "xbo=" then replaceChar = "z" elseif theb64 == "xbs=" then -- with caron -- English keyboard replaceChar = "Z" elseif theb64 == "xbw=" then replaceChar = "z" -- L elseif theb64 == "xYE=" then -- with slash through -- English keyboard replaceChar = "L" elseif theb64 == "xYI=" then replaceChar = "l" end return replaceChar end

My Textlistener to remove or replace all characters that cause a problem looks like this:

local function textListener(event) if (event.phase == "began") then theEnteredText = event.target.text elseif event.phase == "editing" then -- Remove unwanted characters local newChar = event.newCharacters -- local oldText = event.oldText this does not work if event.oldText contains characters like \ local replaceChar = "" if newChar then replaceChar = removeCharsWithError(newChar) if theEnteredText == "" and replaceChar ~= "" then event.target.text = replaceChar elseif replaceChar ~= "" then event.target.text = theEnteredText..replaceChar end replaceChar = "" end theEnteredText = event.target.text -- END Remove unwanted characters end end

​On the App I convert the values that are to be sent with this code:

(The combination “/>” is also causing a problem)

local doEncode = function(theString) if theString ~= "" then -- %% in lookfor is replaced with single % lookfor = '%%'; replacewith = "!!!PERCENT!!!" theString = string.gsub(theString,lookfor,replacewith); lookfor = '/\>'; replacewith = "/XXXgtXXX" theString = string.gsub(theString,lookfor,replacewith); local mime = require("mime") theString = mime.b64(theString) end return theString end

I don’t understand why you need all that.  I have a similar configuration to you and it works with all character sets (including CJK).

I use the  utf8  library rather than the standard string library.  I then use this function to remove the problematic chars - those with a code point above 65535 and then POST to my server.

function stripProblemChars(s) local res = "" for i = 1, utf8.len(s) do local c = utf8.sub(s, i, i) if utf8.codepoint(c) \<= 65535 then res = res .. c end end return res end

I use utf8_general_ci for the database and have never had a “string problem”.