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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改