在变量中添加html

Alv*_*Mok 1 php cakephp

我正在尝试<br>在变量中添加一个html标记(在下面标记),但是当页面被渲染时,它被识别为纯文本.我不确定我哪里出错了.

PS不确定是否重要:我正在使用Cakephp.它是自定义帮助程序类中的变量.

App::uses('AppHelper', 'View/Helper');

class ComaHelper extends AppHelper {
    public $helpers = array('Time');

    public function coma($array, $name) {
        $prefix = ''; 
        $result = '';
        foreach ($array as $key => $value) { 

            $result .= $prefix . $value;

            if ($name == 'condition') { 
                $prefix = ', <br>'; // it's shown as plain text on the page
            } else { 
                $prefix = ', '; 
            }
        } 
        return $result;
    } 
}
Run Code Online (Sandbox Code Playgroud)

这页纸:

<?php echo h($this->Coma->coma($post['Condition'], 'condition')); ?>
Run Code Online (Sandbox Code Playgroud)

gmp*_*nos 5

您使用的h()功能在您的视图中存在问题:

此函数是htmlspecialchars的便捷方法

http://api.cakephp.org/2.3/function-h.html

检查结果:

<?= h('<br>') ?>;
Run Code Online (Sandbox Code Playgroud)