110 likes | 332 Views
PHP: introduction. Speaker: Chin-Cheng Chang Date:2007.3.14. Basic Syntax. file name: *.php start: <?php end: ?> end each command: ; variable: $ xxx constant: define(“ xxx ”, x ) annotations: // or /* …… */. Output. echo " something " ; echo $variable;
E N D
PHP: introduction Speaker: Chin-Cheng Chang Date:2007.3.14
Basic Syntax • file name: *.php • start: <?php • end: ?> • end each command: ; • variable: $xxx • constant: define(“xxx”, x) • annotations: // or /* …… */
Output • echo "something"; • echo $variable; • echo CONSTANT; • <br> //換行符號
Echo <?php // test echo command echo "Hello, World!"; /* this is a demo for database */ ?> http://stu.csie.ncnu.edu.tw/~94321517/demo1.php
Variables <?php $text = "World!"; echo "Hello, $text"; echo 'Hello, $text'; ?> http://stu.csie.ncnu.edu.tw/~94321517/demo2.php
Input(1/2) • get <form action="xxx.php" method="get"><input type="text" name="user"><input type="text" name="password"><input type="submit" value="enter"></form>http://stu.csie.ncnu.edu.tw/~beautidays.99/demo3.php • Post <form action="xxx.php" method=“post"><input type="text" name="user"><input type="text" name="password"><input type="submit" value="enter"></form>http://stu.csie.ncnu.edu.tw/~beautidays.99/demo4.php
Input(2/2) • <?php if ($HTTP_POST_VARS['user']) $user_get=$HTTP_POST_VARS['user']; if ($HTTP_POST_VARS['password']) $password_get=$HTTP_POST_VARS['password']; if ($HTTP_GET_VARS['user']) $user_get=$HTTP_GET_VARS['user']; if ($HTTP_GET_VARS['password']) $password_get=$HTTP_GET_VARS['password']; echo "user=" . $user_get; echo "password=" . $password_get;?>http://stu.csie.ncnu.edu.tw/~beautidays.99/xxx.phps
Loop • for (initial state; condition; repeat state){ command;} • for ($i=1; $i<=10; $i++){echo $i . '<br>';} • http://stu.csie.ncnu.edu.tw/~94321517/demo5.php
stu.csie.ncnu.edu.tw • Create a directory under your home directory • mkdir $HOME/www • You may name your default homepage as: • index.html or index.htm or index.php • http://stu.csie.ncnu.edu.tw/~username/ • http://stu.csie.ncnu.edu.tw/~94321517/ • Reference • http://php.igt.com.tw/
Homework #2 • 9x9 Multiplication Table • Mail your source code (with include files, if any) to TA db-ta@ipv6.club.tw • Email Subject: [Database HW2] 92321036 • You can also mail the URLs only. • Two URLs: one for source code (hw2.phps) and one for execution (hw2.php). • Add these hyperlinks to your “database952.html”. • Due: Tuesday 3/20 11:59AM
link指令 • ln 被link的檔案 新增的檔案 ex. ln hw2.php hw2.phps