dtoaillwk759656786 2019-05-21 06:54
浏览 74

htmlentities()不能以php格式运行

htmlentities is not wroking, it should escape quotes but is does not.

<?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>

You can see 1 line is comment, If I pass a value with quotes in htmlentites(), It outputs the value without quotes, But If I am passing a value from my form, suppose I passed "hello". " " are included. And store this value in php variable and then pass this variable in htmlentites(). It shows output in "", But it should ignore quotes.

  • 写回答

1条回答 默认 最新

  • donglei1699 2019-05-21 07:13
    关注

    There is difference in how you are using the both htmlentities function. If you want to imitate how the first one will work, the one that is commented out should look like this:

    htmlentities('"hello"' ,ENT_QUOTES);

    In your example in the commented out function call, the quotes serve as part of the function, you are passing a parameter like that, so they never even get to be parsed by the function.

    The purpose of the htmlentities is not to strip away characters, but to escape them, so you will never see a sign missing. The use of html entities is for example to print a string in the html like <p>. If not passed through htmlentities it will render a html p tag, if passed through htmlentities like htmlentities('<p>') it will print exaclty that string.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。