简体   繁体   中英

html5 database save '?!& etc as special characters in the html5 database

i Have an HTML5 application where I am trying to save all special characters as special chars

for example

eihefrgredirngfdig'dfdfgdfgg... i want the ' to be saved as a special char. is there a way to do a string replace?

case 5:
            tx.executeSql('CREATE TABLE IF NOT EXISTS notes(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, now, created DATETIME, title, note)');
            tx.executeSql('INSERT INTO notes(now, created, title, note) VALUES(?, ?, ?, ?)', [now, mytime, notetitle, notenote]);    

everything else is working. i just want to be able to replace any and all special chars with the html5 special char equivalent. does anyone have any suggestions on hosw I can string replace? I have done it in php but I cant seem to get it to work properly in javascript.

There is no function which you could simple use. However I don't know your tx.executeSql() function but it looks like a prepaird statment (just wired that you use the tag javascript) there you don't need to care about correct escaping the input strings the database framework should handle that itself.

function myReplace(instr) {
    instr.replace("'", "\\'").replace("?","\\?");
}

The code above masks the input chars ' and ? , it can be simple extended for you needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM