drwn65609 2016-09-12 09:06
浏览 72
已采纳

使用php条件语句用echo打印图像

Hey I'm trying to use php to display an image for each day of the week. I've used the date("D") function to do this but my code doesn't seem to be working. Can someone please take a quick look at it?

<?php
$today = date("D");

if ($today == "Sun")
    echo "Today is Sunday" <img src = 'C:\Users\A1\Documents\2016\Semester 2\ISYS 227\Tutorials\images\sun.jpg'/>;
    elseif ($today == "Mon")
        echo "Today is Monday. <img src = 'C:\Users\A1\Documents\2016\Semester 2\ISYS 227\Tutorials\images\mon.jpg'/>;
    elseif ($today == "Tue")
        echo "Today is Tuesday". <img src = 'C:\Users\A1\Documents\2016\Semester 2\ISYS 227\Tutorials\images\tue.jpg'/>;
    elseif ($today == "Wed")
        echo "Today is Wednesday". <img src = 'C:\Users\A1\Documents\2016\Semester 2\ISYS 227\Tutorials\images\wed.jpg'/>;
    elseif ($today == "Thur")
        echo "Today is Thursday". <img src = 'C:\Users\A1\Documents\2016\Semester 2\ISYS 227\Tutorials\images\thur.jpg'/>';
    elseif ($today == "Fri")
        echo "Today is Friday. <img src = 'C:\Users\A1\Documents\2016\Semester 2\ISYS 227\Tutorials\images\fri.jpg'/>;
    elseif ($today == "Sat")
        echo "Today is Saturday. <img src = 'C:\Users\A1\Documents\2016\Semester 2\ISYS 227\Tutorials\images\sat.jpg'/>;
    else    
    echo "I do not know the day of the week.";

?>
  • 写回答

2条回答 默认 最新

  • dsft8327 2016-09-12 09:10
    关注

    You have closed off your quotes too early

    echo "Today is Sunday" <img src = ''/>;
    

    should be:

    echo "Today is Sunday <img src = ''/>" ;
    

    Removed image source to make it easier to read.

    Also, as pointed out in the comments, use relative path.

    I have tested this and it works.

    Full Code:

    <?php
    $today = date("D");
    
    if ($today == "Sun")
        echo "Today is Sunday <img src = 'images/sun.jpg'/>" ;
        elseif ($today == "Mon")
            echo "Today is Monday. <img src = 'images/mon.png'/>";
        elseif ($today == "Tue")
            echo "Today is Tuesday. <img src = 'images/tue.jpg'/>";
        elseif ($today == "Wed")
            echo "Today is Wednesday. <img src = 'images/wed.jpg'/>";
        elseif ($today == "Thur")
            echo "Today is Thursday. <img src = 'images/thur.jpg'/>";
        elseif ($today == "Fri")
            echo "Today is Friday. <img src = 'images/fri.jpg'/>";
        elseif ($today == "Sat")
            echo "Today is Saturday. <img src = 'images/sat.jpg'/>";
        else    
        echo "I do not know the day of the week.";
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)