如果我之前有“if”语句,为什么我会一直收到语法错误?

时间:2014-08-28 20:50:48

标签: php syntax

嗨,有人可以向我解释,如果我之前有一个“if”状态,为什么我会遇到意外的其他事情?

PHP

<?php if($post_image=="") echo "There is no image" else echo '<img src="../img/'.$post_image.'">' ?>

2 个答案:

答案 0 :(得分:3)

您需要使用分号终止语句:

<?php if($post_image=="") echo "There is no image"; else echo '<img src="../img/'.$post_image.'">'; ?>

答案 1 :(得分:1)

你错过了半冒号。你有:

<?php if($post_image=="") echo "There is no image" else echo '<img src="../img/'.$post_image.'">' ?>
                                                  ^---- here                         and here ---^

您的需求:

<?php if($post_image=="") echo "There is no image"; else echo '<img src="../img/'.$post_image.'">'; ?>