2012-11-03 43 views
0

你好,我有这个变量是字符串。如何在HTML标签中打印php代码?

$这 - > product_output_html = < < < HTML

某些HTML代码

  HTML;

我想诠释,他的班级考试增加一个PHP for循环这样一个

如果($管理 - >错误){的foreach($管理 - >错误,错误$){ 回声'。$错误。 ''; }}

我试图添加,但不工作。我在class =“test”>之后和测试之前添加了'',但仍然不起作用。我做错了什么?

非常感谢

+2

代码字符串,包括定界符段内不起作用。如果你的意思是别的,请给出一个你正在尝试的完整例子。 – mario

回答

0

尝试像

$this->product_output_html = 'Start of html code as a string'; 
if ($admin->errors) { 
    foreach ($admin->errors as $error) { 
    $this->product_output_html .= '<br />'.$error; 
    } 
} 
$this->product_output_html .= '<br />End of html code as a string'; 
echo $this->product_output_html; 
0

更换

echo ".$error."; 

echo $error;