如何在HTML标签中打印php代码?

问题描述:

Hello i'm having this variable which is string.

$this->product_output_html = <<< HTML

Some HTML Code

  HTML;

I want int he class test to add a php for loop like this one

if ($admin->errors) { foreach ($admin->errors as $error) { echo ''.$error.''; } }

i have tried to add but is not working. i added '' after the class="test"> and before the of the test but still is not working. what i'm doing wrong?

thanks a lot

try something like

$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;

replace

echo ".$error.";

with

echo $error;