dqb77047 2013-11-04 03:48
浏览 47
已采纳

语法错误php代码我无法回显变量

I'm having some problems with this code in PHP echo, I want if variable if empty then show an image name "no-registrado.png"

<?php echo $registro ?: "no-registrado.png"; ?>

the error: Parse error: syntax error, unexpected ':' in /Republica-Dominicana/negocios.php on line 199

<img src="../imagenes/admin/<?php echo $registro ?; "no-registrado.png" ?>" Alt="Registrado" title="Registrado" width="20" height="20"/>
  • 写回答

2条回答 默认 最新

  • douti19680318 2013-11-04 04:01
    关注

    Short form of the ternary operator ($registro ?: "no-registrado.png") is available since PHP 5.3. Probably your current version of PHP is less than 5.3.

    You can use full form if you have PHP < 5.3:

    $registro ? $registro : "no-registrado.png"
    

    Also, in your code, you have semicolon in the place where you need use colon.

    <?php echo $registro ?; "no-registrado.png" ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?