【发布时间】:2012-05-16 18:05:21
【问题描述】:
我有以下代码,它的工作方式完全符合我的预期:
<?php if ($a - $b < 1)
echo $text;
elseif ($a - $b >= 1)
echo $a - $b;
else
echo $a; ?>
不过,现在我还想根据 IF 语句的结果在 echo 中添加一些 HTML。
<?php if ($a - $b < 1)
echo $text;
elseif ($a - $b >= 1)
echo $a - $b;
<input type="button" value="<?php echo $button_txt; ?>" id="button" class="button" />
else
echo $a;
<input type="button" value="<?php echo $button2_txt; ?>" id="button" class="button" /> ?>
当我这样做时,我收到以下错误:Parse error: syntax error, unexpected '<input>)。
有没有办法在 IF 语句的 echo 部分中同时包含变量和 HTML?
【问题讨论】:
-
HTML
<input>标签是否应该是 if/else 链的一部分?如果是这样,您还需要{},否则您将在else处收到语法错误。
标签: php html input if-statement echo