dongzouya5792 2015-07-15 11:59
浏览 43
已采纳

在OpenCart中正确回显PHP变量中的HTML标记

I am trying to directly output HTML stored within my MySQL database as HTML, but the browser is rendering it as plain text.

I am working within OpenCart so I am not sure if there are references in other pages that may be affecting my code.

This is where I am defining the variable from the MySQL array

$results = $this->model_catalog_manufacturer->getManufacturers();
   foreach ($results as $result) {
      if (is_numeric(utf8_substr($result['name'], 0, 1))) {
            $key = '0 - 9';
        } else {
            $key = utf8_substr(utf8_strtoupper($result['name']), 0, 1);
        }

        if (!isset($data['categories'][$key])) {
            $data['categories'][$key]['name'] = $key;
        }

        $data['categories'][$key]['manufacturer'][] = array(
            'name' => $result['name'],
            'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $result['manufacturer_id']),
            'image' => $result['image'],
            'banner' => $result['banner'],
            'blurb' => $result['blurb'],
        );
    }

$data['brand_blurb'] = $manufacturer_info['blurb'];

This is where I am echoing the variable

<div class="brand_description"><?php echo $brand_blurb; ?></div>

Do you know what I might be doing wrong? I am still new to PHP so I appreciate the help.

Thank you

  • 写回答

1条回答 默认 最新

  • douchun6221 2015-07-15 12:04
    关注

    You declare $data['brand_blurb'] but you echo $brand_blurb. Change one of the two.
    so either:

    $brand_blurb = $manufacturer_info['blurb'];
    

    or:

    <div class="brand_description"><?php echo $data['brand_blurb']; ?></div>
    

    EDIT:

    Maybe for some reason the characters are converted to Entity Numbers freeformatter.com.
    for example <h1>testing</h1> => &lt;h1&gt;testing&lt;&#47;h1&gt;

    Try the following, html_entity_decode() php.net

    <div class="brand_description"><?php echo html_entity_decode($data['brand_blurb']); ?></div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置