dongqiuqiu4736 2015-07-30 18:28
浏览 101

我可以将带有json_encode的字符串转换回textarea中的可读html吗?

I have created a textarea with a wysywig text editor on it. The user would click into the textarea and start typing like any text editor. They would then save the form with that text and the data would then be saved into the database with $data['description'] = json_encode($description_data); this would save encoded string into the database.

The following is what I would get in the db column:

""<h1>test<\/h1>

<p>paragraph<\/p>

<p><u><em><strong>some text<\/strong><\/em><\/u><\/p>
""

The reason this is in this format is because it is part of some json output as part of an api and the app needs the text to be converted in this format.

My main issue is this, when the admin goes to edit that data in the textarea the text is added back in as the data above which is expected as you can see below:

the text editor with jsin in it

This text needs to have none of this wrapping the content and be plain normal html in the textarea. Is this possible?

Here is the controller function below:

public function store(Offer $offer)
    {

        $offerId = $offer['id'];

        $data = Input::except('image','featured');
        //$featured_data = array( 'offer_date' => $data['offer_date'], 'starttime' => $data['offer_start_time'], 'endtime' => $data['offer_end_time'] );
        $description_data = $data['description'];
        $validation = Validator::make($data, Offer::$rules);


        if ($validation->fails()) {
            return redirect('offers')->with('message', $validation->errors());
        } else {
            $file = Input::file('image');
            $filename = date('Y-m-d-H')."-".$file->getClientOriginalName();

            $path = storage_path('app/uploads/' . $filename);
            Image::make($file->getRealPath())
              ->resize(600, 600)
              ->save($path);

              $data['image'] = 'storage/app/uploads/'.$filename;
              $data['description'] = json_encode($description_data);

            Offer::create( $data );
            return redirect('offers')->with('message', 'Offer added!');
        }

    }

And in the form I have got this:

<div style="clear: both;" class="form-group">
    {!! Form::label('description', 'Offer Description:') !!}
    {!! Form::textarea('description', null, array('id'=>'editor1','class' => 'ckeditor form-control')) !!}
</div>

Hopefully this can be achieved.

  • 写回答

2条回答 默认 最新

  • douzhanjia0773 2015-07-30 18:44
    关注

    Just use json_decode when outputing. it do the opposite of json_encode.

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答