Well, I have these string prototypes for work, however I don't understand what they do for sure.
String.prototype.php_htmlspecialchars = function() { return this.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); } String.prototype.php_unhtmlspecialchars = function() { return this.replace(/"/g, '"').replace(/>/g, '>').replace(/</g, '<').replace(/&/g, '&'); } String.prototype.php_addslashes = function() { return this.replace(/\\/g, '\\\\').replace(/'/g, '\\\''); } String.prototype._replaceEntities = function(sInput, sDummy, sNum) { return String.fromCharCode(parseInt(sNum)); } String.prototype.removeEntities = function() { return this.replace(/&(amp;)?#(\d+);/g, this._replaceEntities); } String.prototype.easyReplace = function (oReplacements) { var sResult = this; for (var sSearch in oReplacements) sResult = sResult.replace(new RegExp('%' + sSearch + '%', 'g'), oReplacements[sSearch]); return sResult; }
Basically, I need to replace all instances of double quotes ("),>, <, single quotes ('), etc. etc. Basically the same things as htmlentities () in php, but I need replace them with an empty string so that they are removed from the text.
Can any of the above functions be used? If not, how can I do this in Javascript? Can I use substitution in a string?
Please someone help me here. I put this text in the selection box and will be entered into the database when the form is submitted. Although, I use PHP to remove all of these characters, however, I find it difficult to find a way to do this in Javascript.
Thanks:)
source share