php encoding issue htmlentities

后端 未结 2 1095
梦如初夏
梦如初夏 2021-01-07 14:14

I have user input and use htmlentities() to convert all entities. However, there seems to be some bug. When I type in

ääää öööö üüüü ääää

I

相关标签:
2条回答
  • 2021-01-07 14:36

    You must manually specify the encoding (UTF-8) for htmlentities():

    echo htmlentities("ääää öööö üüüü ääää", null, "UTF-8");
    

    Output:

    ääää öööö üüüü ääää
    
    0 讨论(0)
  • 2021-01-07 14:41

    it is important that 3th parameter of htmlentities matches the character set that uses the post. I supouse, you are NOT submiting utf8, as it is the default in htmlentities

    in PHP

     $post = htmlentities ( $post, ENT_COMPAT, 'ISO-8859-1')  // or whatever  
    

    in Form

     <form action="your.php" accept-charset="ISO-8859-1">
    

    anyway, actualy I recommend you to use utf8

    0 讨论(0)
提交回复
热议问题