我必须在表单中创建一个登录用户将插入用户名和密码.我必须确保不处理html实体,并且我也不能允许处理单引号或双引号.我必须回显输入到表单中的数据并显示它.
我必须使用htmlentities和str_replace.我的htmlentities正确,但我不确定如何利用str_replace函数来替换用户可能在表单中输入的单引号和双引号.任何帮助都是极好的.
这是我目前的PHP(有效)
<?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; ?>
Run Code Online (Sandbox Code Playgroud)
Sco*_*ion 14
我想你想要这样.. ..请检查
$yourPostVariable = "scor\"pi'on";
//$name = str_replace(array("'", "\""), "", htmlspecialchars($yourPostVariable ) );
echo str_replace(array("'", "\"", """), "", htmlspecialchars($yourPostVariable ) );
Run Code Online (Sandbox Code Playgroud)
$keyItem = str_replace ("'","\'",$keyItem);
Run Code Online (Sandbox Code Playgroud)
这将用“转义”单引号 \' 替换单引号。