php htmlentities解码textarea [英] php htmlentities to decode textarea

查看:71
本文介绍了php htmlentities解码textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本区域,我想输入文本区域并将其合并在一起.除转义引号外,其他所有内容均正常运行.例如,test's输出为test/'s

I have a text area and I would like to take the input of the text area and merge it all together. Everything works fine except that it's escaping the quotes. For example test's is outputted as test/'s

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

To fix this I tried htmlenttries such as,

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

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

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

This should work according to the html_entity_decode manual (unless I read it wrong which could very likely be the case)

推荐答案

该解决方案可能适合您去除斜杠.

The solution is probably for you to strip slashes.

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

The slashes are automatically added when data comes from POST or GET. This is known as magic quotes and by default are enabled.

您可以使用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

这篇关于php htmlentities解码textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆