简体   繁体   English

html5数据库将'?!&等另存为html5数据库中的特殊字符

[英]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 我有一个HTML5应用程序,我试图将所有特殊字符另存为特殊字符

for example 例如

eihefrgredirngfdig'dfdfgdfgg... i want the ' to be saved as a special char. eihefrgredirdirffdfdfgdfgg ...我希望将'保存为特殊字符。 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. 我只希望能够用html5特殊字符替换任何和所有特殊字符。 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. 我已经在php中完成了操作,但似乎无法在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. 但是我不知道您的tx.executeSql()函数,但是它看起来像一个预配对的语句(只是有线连接,您使用标签javascript),那里您不需要关心正确地转义数据库框架应该处理的输入字符串本身。

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

The code above masks the input chars ' and ? 上面的代码屏蔽了输入字符'? , it can be simple extended for you needs. ,可以根据您的需要进行简单扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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