【问题标题】:Trying to load json data containing an html tags into html file尝试将包含 html 标签的 json 数据加载到 html 文件中
【发布时间】:2017-11-27 02:48:48
【问题描述】:

我有一个包含 HTML 标签的 json 响应:

{
    "total": 15,
    "per_page": 15,
    "current_page": 1,
    "last_page": 1,
    "next_page_url": null,
    "prev_page_url": null,
    "from": 1,
    "to": 15,
    "data": [
        {
            "id": 48,
            "title": "Lamb Ribs with mashed potatoes",
            "body": "<p>Lamb Ribs with Mashed Potatoes:<br />230 grams of lamb ribs<br />Marinade:( Teaspoon pomegranate molasses, 1 tablespoon lemon juice, 1 teaspoon tomato paste, 1 teaspoon olive oil, salt, black pepper, &nbsp;oregano)<br />Marinate the ribs for at least 2 hours. &nbsp;Heat a non stick grilling skillet and grill the ribs from both sides untill done.<br /><br />Mashed Potatoes:<br />130 grams of peeled potatoes. Boil until cooked and let to cool.<br />Add a tablespoon of milk, salt, garlic powder and black pepper and mash together.<br />Serve immediately.<br /><br />545 calories<br />24.7 g fat<br />29.8 g carb<br />3.1 g fiber<br />48.3 g protein<br />.</p>",
            "excerpt": "",
            "format": "standard",
            "type": "recipe",

注意:上面的json不是完整的,因为它是长响应文件。

上面的json我已经解码了:

$post = json_decode($response);

在视图文件中:

{{$post->body}}

文本已加载,但未按应有的标签格式化。

在查看源代码/chrome 中,它看起来像这样:-

我该如何解决这个问题?

【问题讨论】:

  • 试试:html_entity_decode($post-&gt;body)
  • @VincentDecaux 我试过但没用 ,, {{htmlentities($post->body)}}
  • @瑞安文森特。我可以使用什么功能来发送原始输出?请提供解决方案
  • @Ryan Vincent 我在 laravel 中使用 Blade 模板
  • 我假设您已经找到了答案 - 不管怎样:stackoverflow.com/questions/29253979/…

标签: php html json


【解决方案1】:

通过使用解决:-

{!! $text !!}

【讨论】:

    猜你喜欢
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 2017-06-23
    • 1970-01-01
    相关资源
    最近更新 更多