【问题标题】:How to print php code in HTML tags?如何在 HTML 标签中打印 php 代码?
【发布时间】:2012-11-03 00:32:22
【问题描述】:

你好,我有这个变量,它是字符串。

$this->product_output_html =

一些 HTML 代码

HTML;

我希望在类测试中添加一个像这样的 php for 循环

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

我已尝试添加但无法正常工作。我在 class="test"> 之后和测试之前添加了 '' 但仍然无法正常工作。我做错了什么?

非常感谢

【问题讨论】:

  • 代码在字符串中不起作用,包括 heredoc 部分。如果您的意思是别的,请展示您正在尝试的完整示例。

标签: php html echo


【解决方案1】:

试试类似的东西

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

【讨论】:

    【解决方案2】:

    替换

    echo ".$error.";
    

    与

    echo $error;
    

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      相关资源
      最近更新 更多