How to use str_replace to replace single and double quotes
I need to create a login in a form where the user inserts the username and password. I have to ensure that html objects are not processed and I cannot allow single quotes or double quotes to be processed. I have to echo the data entered into the form and display it.
I have to use htmlentities and str_replace. I have htmlentities correct, but I'm not sure how to use the str_replace function to replace the single and double quotes that the user can enter into the form. Any help would be awesome.
Here is my current PHP (which is working)
<?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; ?>
+3
source to share
7 replies
I think you want this way .. please check
$yourPostVariable = "scor\"pi'on";
//$name = str_replace(array("'", "\""), "", htmlspecialchars($yourPostVariable ) );
echo str_replace(array("'", "\"", """), "", htmlspecialchars($yourPostVariable ) );
+13
source to share