4

我有一个文本区域,我想获取文本区域的输入并将其合并在一起。一切正常,只是它转义了引号。例如test's输出为test/'s

为了解决这个问题,我尝试了 htmlenttries,例如,

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

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

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

4

3 回答 3

7

解决方案可能是让您去除斜线。

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

于 2009-12-25T10:24:34.027 回答
2

您需要使用$encodetext = htmlentities ($inputtext, ENT_QUOTES);which 不会尝试转义单引号和双引号。在此处查看标志htmlentities

于 2011-06-24T02:08:30.113 回答
1

确保您没有在对htmlentitiesand的调用中传递第二个参数html_entity_decode。如果你这样做,他们将以不同的方式转义/取消转义引号。检查和$quote_style文档中参数的描述。htmlentitieshtml_entity_decode

于 2009-12-25T10:23:27.843 回答