2017-11-07 10:04
浏览 624


So I'm trying to store some HTML code in the database and then retrieving it througth the API.

Initial HTML:

<img src="" alt="Google logo">

Then I store in the DB without any further hassle:

$data = $request->only(['content');

$comment = $this->repo->update($data, $id);

If I go to MySQL Workbench, this is the data stored:

<img src="" alt="Google logo">

However, the moment I retrieve it want want to output the HTML as a JSON parameter, it get's slahed all over the face.

This is the json:

{"title": "<img src=\"\" alt=\"Google logo\">"}

I have not applied any transformation nor during insert nor on retrieval.

How can I remove the added extra backslashes? ()

图片转代码服务由CSDN问答提供 功能建议



 &lt; img src =“”alt =“  Google徽标“&gt; 


  $ data =  $ request-&gt; only(['content'); 
 $ comment = $ this-&gt; repo-&gt; update($ data,$ id); 

如果我去MySQL Workbench,这是存储的数据:

 &lt; img src =“  google_80wht.gif“alt =”Google徽标“&gt; 

但是,我检索它的那一刻想要输出HTML作为JSON参数,它会得到 这是json:

  {“title”:“&lt; img src = \”https:  // \“alt = \”Google徽标\“&gt;”} 

我没有应用任何转化 插入时也不插入 ieval。

如何删除添加的额外反斜杠? ()

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongtun2572 2017-11-07 10:13

    Try json_decode(your_data) this should work.

    解决 无用
    打赏 举报
  • dongle3217 2017-11-07 10:16

    I have not applied any transformation nor during insert nor on retrieval.

    You converted it to JSON. That is a transformation.

    it get's slahed

    The slashes are needed.

    Without them this happens:

    "<img src="h
    ^         ^^
    |         ||
    |         |Error
    |         End of string
    Start of string

    The data doesn't contain the slashes, just the JSON representation of it. When you parse the JSON the escape sequences will be consumed and you will get your original string back.

    解决 无用
    打赏 举报

相关推荐 更多相似问题