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

  • Home
  • SEARCH
  • 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 9268605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:53:55+00:00 2026-06-18T14:53:55+00:00

I have to create a login in form which a user will insert a

  • 0

I have to create a login in form which a user will insert a username and a password. I have to ensure that html entities are not processed, and I can not allow single quotes or double quotes to be processed either. I must echo the data entered into the form and display it.

I must use htmlentities and str_replace. I have the htmlentities correct, but am unsure on how to utilize the str_replace function to replace the single and double quotes that the user might enter into the form. Any help would be awesome.

Here is my current PHP (which works)

<?php
$username = htmlspecialchars($_POST['username']);
$password    = htmlspecialchars($_POST['password']);
$comment = htmlspecialchars($_POST['comment']);
?>
<html>
<body>
Your username is: <?php echo $username; ?><br />
Your password: <?php echo $password; ?><br />
Your Comment was: <?php echo $comment; ?>

  • 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-06-18T14:53:56+00:00Added an answer on June 18, 2026 at 2:53 pm

    First of all, it is always better to check for the unwanted characters and get back to the user, than silently stripping them. Say, a user added a quote to their password, you removed it, and so they won’t be able to login at all! So it’s better to check and tell the user instead:

    if (!ctype_alnum($username)) { 
        $errors[] = "Only letters and numbers allowed in username";
    }
    ...
    if ($errors) {
        echo "You've got some errors, please fix them: ". implode("<br>", $errors);
    } else {
        // proceed with normal flow
    

    But in this specific case I would advise against replacing any characters. Imagine Shaquille "Shaq" O'Neal is going to register on your site. What’s the point in stripping him of all those quotes? Let alone the password, where use of punctuation is strongly encouraged.

    After all, those quotes don’t do any harm, if you properly handle them.

    • for HTML, simply use htmlspecialchars() with ENT_QUOTES attribute:

        Your username is: <?= htmlspecialchars($username, ENT_QUOTES) ?><br />
      
    • for SQL, use prepared statements to avoid any problems with quotes

    But just for sake of literal answer, here is how to remove quotes (or any other characters and even multi-character substrings) in PHP

    $yourVariable = "scor\"pi'on";
    $substringsToRemove = ['\'', '"'];
    $yourVariable = str_replace($substringsToRemove, "", $yourVariable);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Login dialog that can create an alert dialog when the user
Hi I want to create a WCF service that have login method, which is
i have created one login and register view in that view after login user
I have created a User called Student and Teacher that can login into the
I have a simple authorization page which intends the user to type login and
I have a form in my site_base.html which extends to all of my templates.
i have one xib and that xib i put on username, password, and one
I have to create a simple form that uses JSP for the view with
I have a members site which requires login where members create web pages with
I have a login window that I open as a Chrome installed Extension (will

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.