Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3604954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:03:47+00:00 2026-05-18T21:03:47+00:00

Ok, I have these string prototypes to work with, however, I don’t understand what

  • 0

Ok, I have these string prototypes to work with, however, I don’t understand what they do exactly.

String.prototype.php_htmlspecialchars = function()
{
 return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

String.prototype.php_unhtmlspecialchars = function()
{
 return this.replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/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, what I need to do is replace all instances of double quotes (“), >, <, single quotes (‘), etc. etc.. Basically the same stuff that htmlentities() in php changes, but I need to replace them with an empty string, so that they are removed from the text.

Can I use any of the functions above? If not, how can I accomplish this in Javascript? Can I use a replace on the string?

Please, someone, help me here. I am placing this text into a select box and will be inputted into the database upon submitting of the form. Though, I am using PHP to remove all of these characters, however, I’m having difficulty finding a way to do this in Javascript.

Thanks 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:03:48+00:00Added an answer on May 18, 2026 at 9:03 pm

    Remove special characters (like !, >, ?, ., # etc.,) from a string using JavaScript:

    var temp = new String('This is a te!!!!st st>ring... So??? What...');
    document.write(temp + '<br>');
    temp =  temp.replace(/[^a-zA-Z 0-9]+/g,'');
    document.write(temp + '<br>');
    

    jsFiddle

    Edit:

    If you don’t want to remove dot(.) from string:

    temp =  temp.replace(/[^a-zA-Z 0-9.]+/g,'');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does the Prototype Javascript library have a selector that's equivalent to jQuery's :contains() ?
We typically interface with a RDBMS through SQL. I.e. we create a sql string
In Javascript, we can call methods on string literals directly without enclosing it within
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
There are a number of great Javascript libraries\frameworks out there (jQuery, Prototype, MooTools, etc.),
I need to compare 2 strings as equal such as these: Lubeck == Lübeck
We have an old page written in Classic ASP that makes calls to an
I am working on a Django application which allows a user to upload files.
My company's main application is mostly written in C++ (with some Delphi code and
I would like to know what is the most efficient and practical way of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.