2012-11-03 42 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;