查看: 2127|回复: 0

[教程] 【一网打尽】Raspberry Pi Course Week 6 – Day 5 (Programming PHP)

[复制链接]
  • TA的每日心情
    开心
    2016-8-4 10:56
  • 签到天数: 242 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2015-3-28 13:50:06 | 显示全部楼层 |阅读模式
    分享到:

    In the previous day you explored how to install PHP and use a simple function within an HTML page to display some information about the server,

    <?php phpinfo(); ?>

    The <? is called an open delimiter and this is where you will place the PHP code.  When you are finished creating the PHP code you will need to let PHP that you are finishing this code with a closing delimiter which is a ?>.

    Notice that the function phpinfo(); ends with a semi colon. This is letting PHP know that we have finished with the line of code.  This is very similar to a sentence and ending it with a full stop or period.  The PHP will not be delivered to the web browser because the server will run the PHP code and return html or java code.

    PHP code can become quite long and a complex spanning a number of pages.  To keep track of what is going on it is always a good idea to use comments.  Comments allow you to make notes about the code to remind yourself and others of what is going on without going into the detail of the code.


    <?php

                    /* This is a comment and the function below displays php information */
    phpinfo();

    ?>

    All comments are ignored by PHP and are only displayed in the code.  This type of comment is known as a multiline comment because it can span multiple lines.

    <?php

                    /* This is a commen and

                    The function below

                    Displays php information */

                    phpinfo();

    ?>

    Another type of comment is the single line comment.  Two forward slashes // are used for this.

    <?php

                    // this is a single line comment
    phpinfo();
    ?>


    We will create a php page that will display the current date.  Create a new page by enter the following.

    $ cd /var/www

    $ sudo nano datepage.php

    Enter the following code into the datepage.php document


    <html>

    <head>
    <title>The date</title>

    </head>

    <body>The date is

    <? php

                //this will display the date

                echo date(“y/m/d”);

    ?>

    </body>

    </html>


    Save the file.  CTRL-X and confirm that you want to save it.

    Open a web browser and in the address bar enter the following.

    http://localhost/datepage.php

    The output will display the current date.

    The date is 2014/04/12.


    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-11-19 13:19 , Processed in 0.114360 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.