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

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题