Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
htmlentities()在php表单中不起作用_Php_Html - Fatal编程技术网

htmlentities()在php表单中不起作用

htmlentities()在php表单中不起作用,php,html,Php,Html,htmlentities不是wroking,它应该转义引号,但不是 <?php session_start(); session_regenerate_id( true ); if(isset($_REQUEST['sub'])){ echo $name = htmlspecialchars($_REQUEST['email'] ); echo $pswd = $_REQUEST['pswd']; echo $abc = htmlentities($pswd ,EN

htmlentities不是wroking,它应该转义引号,但不是

<?php
session_start();
session_regenerate_id( true );
if(isset($_REQUEST['sub'])){
    echo $name = htmlspecialchars($_REQUEST['email'] );
    echo $pswd = $_REQUEST['pswd'];
    echo $abc = htmlentities($pswd ,ENT_QUOTES, "UTF-8");
    //echo $pswd = htmlentities("hello" ,ENT_QUOTES);   
}
?>


<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Login form</h2>
  <form action="" method="POST">
    <div class="form-group">
      <label for="email">Email:</label>
      <input type="email" class="form-control" id="email" placeholder="Enter email" name="email" required>
    </div>
    <div class="form-group">
      <label for="pwd">Password:</label>
      <input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pswd" required>
    </div>    
    <button type="submit" class="btn btn-primary" name="sub">Submit</button>
  </form>
</div>

</body>
</html>

引导示例
登录表格
电邮:
密码:
提交

您可以看到1行是comment,如果我在htmlentites()中传递一个带引号的值,它将输出不带引号的值,但是如果我从表单中传递一个值,假设我传递了“hello”。”“包括在内。并将该值存储在php变量中,然后将该变量传递到htmlEntes()。它在“”中显示输出,但应忽略引号。

使用这两个htmlentities函数的方式有所不同。如果要模拟第一个选项的工作方式,则注释掉的选项应如下所示:

htmlentities('hello',entu引号)

在您的示例中,在注释掉的函数调用中,引号作为函数的一部分,您正在传递这样一个参数,因此它们甚至无法被函数解析


htmlentities的目的不是去除字符,而是转义字符,这样您就永远不会看到丢失的符号。例如,使用html实体在html中打印字符串,如
。如果未通过htmlentities,它将呈现一个htmlp标记,如果通过htmlentities,如
htmlentities(“”)
,它将精确打印该字符串。

使用两个htmlentities函数的方式有所不同。如果要模拟第一个选项的工作方式,则注释掉的选项应如下所示:

htmlentities('hello',entu引号)

在您的示例中,在注释掉的函数调用中,引号作为函数的一部分,您正在传递这样一个参数,因此它们甚至无法被函数解析


htmlentities的目的不是去除字符,而是转义字符,这样您就永远不会看到丢失的符号。例如,使用html实体在html中打印字符串,如
。如果未通过htmlentities,它将呈现一个htmlp标记,如果通过htmlentities,如
htmlentities(“”)
它将精确打印该字符串。

echo$pswd=$\u请求['pswd'];echo$abc=htmlentities($pswd,ENT_报价,“UTF-8”);检查这两行,我已经准备好了,行了吗?不,不行works@xmastertje|请忽略“UTF-8”这一解决方案failed@xmastertjecan您的
var\u dump
您的
$\u请求['pswd']
echo$pswd=$\u请求['pswd'];echo$abc=htmlentities($pswd,ENT_报价,“UTF-8”);检查这两行,我已经准备好了,行了吗?不,不行works@xmastertje|请忽略“UTF-8”这一解决方案failed@xmastertjecan您的
var\u dump
您的
$\u请求['pswd']