php htmlentities解码textarea

Bro*_*ke. 3 php textarea html-encode html-entities

我有一个文本区域,我想接受文本区域的输入并将它们合并在一起.一切正常,但它正在逃避报价.例如test's输出为test/'s

为了解决这个问题,我试过了很多例子,

<?php $inputtext= $_POST['textinput'];
        $encodetext = htmlentities($inputtext);
        $finaltext = html_entity_decode($encodetext);

        echo '<p>'.$finaltext .'</p>';  ?>
Run Code Online (Sandbox Code Playgroud)

这应该根据html_entity_decode手册工作(除非我读错了,很可能是这种情况)

mau*_*ris 6

解决方案可能是你去除斜线.

当数据来自POST或GET时,会自动添加斜杠.这被称为魔术引号,默认情况下已启用.

您可以使用删除这些斜杠 stripslashes()

<?php

$text = $_POST['txtarea']; // from textarea
if(get_magic_quotes_gpc()){
  $text = stripslashes($text);
  // strip off the slashes if they are magically added.
}
$text = htmlentities($text);
// what htmlentities here does is really to convert:
//   & to &amp;
//   " to &#039;
//  and change all < and > to &lt; and &gt; respectively. this will automatically disable html codes in the text.
echo '<pre>'.$text.'</pre>';

?>
Run Code Online (Sandbox Code Playgroud)

请参阅:http://php.net/manual/en/function.stripslashes.php