1、首先是安装环境,以及php,详见php网站上的信息。如果只是简单的学习,可以使用在线编辑器。第一个程序Hello World!Thisis PHP。
2、<!DOCTYPE html><html><body><?php$x=1;$y=2;$z=$x+$y;echo $z;?></body></html>运行结果:3由上述例子可知,php是弱类型变量,不需要先定义数据类型在赋值。命名规则如下图。
3、<!DOCTYPE html><html><body><?php$x=1;function Test(){$y=2;echo "local variable: $y \n";}Test();echo "globle variable: $x";?></body></html>运行结果: local variable: 2 globle variable: 1
4、条件语句是一个必学的结构语句:<挢旗扦渌;!DOCTYPE html><html><body>媪青怍牙<?php$t=date('h');if ("0"<$t&&$t<"12"){echo "Good morning!";}else if (12<$t&&$t<"24"){echo "Good afternoon!";}else{echo "Good noon!";}?></body></html>运行结果: Good morning!
5、php表单的传送html:<html><head><meta charser="utf-8"><title>Test_for_php</title></head><body><form action="welcome php" method="post">name:<input type="text" name="fname">age:<input type="text" name="age"><input type="submit" value="submit"></form></body></html>php:<!DOCTYPE html><html><body>Welcome <?php echo $_POST["fname"]; ?>!<br>Your age is <?php echo $_POST["age"]; ?> .</body></html>