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条)

报告相同问题?

悬赏问题

  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上
  • ¥15 装完kali之后下载Google输入法 重启电脑后出现以下状况 且退不出去 桌面消失 反复重启没用
  • ¥15 ESP-IDP-BLE配网连接wifi