【问题标题】:echo HTML statement containing a JSON objectecho 包含 JSON 对象的 HTML 语句
【发布时间】:2020-09-26 01:54:52
【问题描述】:

如何在 PHP 中回显这个 HTML 语句?

<area id="6" class="seat" title="Seat: B3" coords="170,469,170,432,179,427,202,427,210,433,210,469"     shape="poly" data-maphilight='{"strokeWidth": 0, "stroke": true, "alwaysOn":true}'>

【问题讨论】:

    标签: php html escaping echo


    【解决方案1】:

    在你的陈述中使用 \ 之前

    喜欢:-

    <?php echo "<area id=\"6\"> </area> ?>
    

    它将允许您在语句中使用 " 而不会出现任何错误。

    【讨论】:

      【解决方案2】:

      您应该首先使用 json_encode 将您的对象编码为 JSON 字符串,然后将其作为属性回显。

      给你。

      <?php
      $json_string = json_encode($your_object);
      
      echo '<area id="6" class="seat" title="Seat: B3" coords="170,469,170,432,179,427,202,427,210,433,210,469" shape="poly" data-maphilight=\''. $json_string. '\'>';
      
      
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-13
        • 1970-01-01
        • 1970-01-01
        • 2011-10-29
        • 2018-01-02
        • 2012-02-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多