php study note 2 --- basic syntax

来源:互联网 发布:网络舆情监测员工资 编辑:程序博客网 时间:2024/05/22 05:54

1. the fisrt php code

root@vinco:/var/www# ls\  index.html  testphp  w3cschool.phproot@vinco:/var/www# mv testphp test.php

<?phpinfo();?>


2. for() foreach() switch-case, if-else,if-elseif-else


root@vinco:/var/www# vim syntax1.php

<html><body><?php        /* for variable and echo  */        $txt="hello world";        echo $txt . " " . ","."vinco<br/>";        /* for if-elseif-else sentence */        $d=date("D");        if($d=="Fri")        {                echo "<br/>Hello!<br/>";                echo "Have a nice weekend!";                echo "See you on monday!<br/><br/>";        }        elseif($d=="Sun")        {                echo "have a nice sunday<br/>";        }        else        {                echo "have a nice workday<br/>";        }        /* for array, for,foreach,switch--case sentence  */        $week=array( "sunday"=>0,"monday"=>1,"tuesday"=>2,"wenesday"=>3,"thursday"=>4,"friday"=>5,"satday"=>6 );        for($day=$week['sunday'];$day <= $week['satday'];$day++)        //foreach($week as $day)        {                switch($day)                {                case 0: echo "today is "."sunday!<br/> ";break;                case 1: echo "today is "."monday!<br/> ";break;                case 2: echo "today is "."tuesday!<br/> ";break;                case 3: echo "today is "."wenesday!<br/> ";break;                case 4: echo "today is "."thursday!<br/> ";break;                default:break;                }                echo "<br/>";        }        /* for function */        function add($x,$y)        {                $total=$x+$y;                return $total;        }        echo "10+100 = ".add(10,100);        /* for form */?>        <form action="welcom.php" method="post">        Name:<input type="text" name="name" /><br/>        Age&nbsp&nbsp&nbsp:<input type="text" name="age" /><br/>        <input type="submit" /><br/>        </form></body></html>




原创粉丝点击