doz15449 2016-09-12 18:38
浏览 45
已采纳

在echo语句中显示html [重复]

This question already has an answer here:

Ok the below information works im just trying to figure my problem is that if that it displays like this title grade...

but i want to put a | inbetween like this

title | grade.

my below code works but if there is no grade it still echos the |,

how can i get it to only echo when there is a value in that field.

because when the field is empty it shows

title |

<div class="sto-info">
<span><?php echo $title; ?> <?php echo '|', $grade; ?></span>
</div>
</div>
  • 写回答

3条回答 默认 最新

  • doucang2831 2016-09-12 18:39
    关注

    You can use a ternary operator:

    <span><?php echo $title; ?> <?php echo $grade ? '|' . $grade : ''; ?></span>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试