douyang5943 2016-10-27 09:55
浏览 57

textarea不提供html标签

This may be a very simple and stupid question, but it's so simple that I don't know what I did wrong.

I'm trying to get the content of a textarea while retaining the formatting (breakline, spaces, etc). but when i tried to post the form, there was no html tags to be found. all I got was plain text.

when I type in the textarea like this:

first line



after 3 br

I expected the result of echo $foo; to be something like this:

first line
<br/>gt;
<br/>gt;
<br/>gt;
after 3 br

but instead, the result of echo $foo; was still like this:

first line



after 3 br

this is the display.php:

<form method="post" action="">
  <textarea name="foo"><?php echo set_value('foo'); ?></textarea>
  <br/>
  <input type="submit" name="submit" value="Submit"/>
</form>

this is the controller:

function form_foo()
{
  $foo = $this->input->post('foo');
  if (get_magic_quotes_gpc())
  {
    $foo = stripslashes($foo);
  }
  $foo = htmlentities($foo);
  echo $foo;
  $this->load->view('display', $this->data);
}

what did I do wrong?

P.S : I'm using codeigniter 3.0 and PHP 5.6.15

  • 写回答

2条回答 默认 最新

  • dqluw20882 2016-10-27 10:16
    关注

    Try this code -

    function form_foo()
    {
        $foo = $this->input->post('foo');
        if (get_magic_quotes_gpc())
        {
            $foo = stripslashes($foo);
        }
    
        //$foo = htmlentities($foo);
    
        echo $foo;
        $this->load->view('display', $this->data);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)