我有一个文本区域,我想获取文本区域的输入并将其全部合并在一起。除了转义引号之外,一切都工作正常。例如test's
输出为test/'s
为了解决这个问题,我尝试了 htmlenttries,例如,
<?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 &
// " to '
// and change all < and > to < and > respectively. this will automatically disable html codes in the text.
echo '<pre>'.$text.'</pre>';
?>
See: http://php.net/manual/en/function.stripslashes.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)