php htmlentities来解码textarea(php htmlentities to decode textarea)

编程入门 行业动态 更新时间:2024-10-26 20:32:03
php htmlentities来解码textarea(php htmlentities to decode textarea)

我有一个文本区域,我想要输入文本区域并将它们合并在一起。 一切工作正常,只是它逃避报价。 例如, test's作为test/'s输出

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

<?php $inputtext= $_POST['textinput']; $encodetext = htmlentities($inputtext); $finaltext = html_entity_decode($encodetext); echo '<p>'.$finaltext .'</p>'; ?>

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

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

To fix this I tried htmlenttries such as,

<?php $inputtext= $_POST['textinput']; $encodetext = htmlentities($inputtext); $finaltext = html_entity_decode($encodetext); echo '<p>'.$finaltext .'</p>'; ?>

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

最满意答案

解决方案可能是为你解开斜杠。

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

The solution is probably for you to strip slashes.

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

You can remove these slashes by using 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>'; ?>

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

更多推荐

本文发布于:2023-08-07 20:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465639.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:htmlentities   php   decode   textarea

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!