1

When I enter quotes in a form and have that data showed in an echo it puts the quotes like this, \"Text Here\". How do I remove the \ from the quotes so it just says "Text Here"?

Code #1

        <form action="index2.php" method="post">
    Enter Your Name: <br>
    <input type="text" name="name" placeholder="Enter Your Name Here"><br>
    Enter Custom Quote: <br>
    <input type="text" name="quote" placeholder="Exe; &quot;I had a dream&quot; "><br>
    <input type="submit" value="Send">
    </form>

Code #2

<html>
<head>
</head>
<body>
    Thank you for sending us your quote <?php echo $_POST["name"]; ?>.
    You quote was <?php echo $_POST["quote"]; ?>
</body>

Jonny Apple
  • 47
  • 1
  • 7
  • See [this question](http://stackoverflow.com/q/3006407/2976720) related to yours, please check the `magic_quotes` setting or use `stripslashes` – B_s Aug 19 '15 at 22:45

1 Answers1

2

If you have PHP Version <5.4.0, then your problem is probably related to magic quotes, which was deprecated in PHP 5.4.0.

Use the stripslashes function.

<body>
    Thank you for sending us your quote <?php echo stripslashes($_POST["name"]); ?>.
    Your quote was <?php echo stripslashes($_POST["quote"]); ?>
</body>

You should also use other functions like htmlspecialchars to decrease the likelihood of someone successfully hacking your code by injecting php code into the form.

DivideByZero
  • 535
  • 4
  • 14