编程语言
首页 > 编程语言> > php htmlentities解码textarea

php htmlentities解码textarea

作者:互联网

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

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

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

        echo '<p>'.$finaltext .'</p>';  ?>

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

解决方法:

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

当数据来自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>';

?>

见:http://php.net/manual/en/function.stripslashes.php

标签:html-encode,php,textarea,html-entities
来源: https://codeday.me/bug/20190724/1519325.html