PHP学习一

来源:互联网 发布:淘宝体检中心虚假交易 编辑:程序博客网 时间:2024/06/04 17:54


<html><head><title>Bob's Auto Parts-Order Results</title></head><body><h1>Bob's Auto Parts</h1><h2>Order Results</h2><p> Order Procesed.</p></body></html>

  • <html> 与 </html> 之间的文本描述网页
  • <body> 与 </body> 之间的文本是可见的页面内容
  • <h1> 与 </h1> 之间的文本被显示为标题
  • <p> 与 </p> 之间的文本被显示为段落

<html><head><title>Bob's Auto Parts-Order Results</title></head><body><h1>Bob's    Auto     Parts</h1><h2>Order Results</h2></body><?php echo '<p> Order Procesed.';echo date('H:i, jS F');echo '</p>';?><?phpecho '<p> order procesed at ' . date('H:i,JS F') . '</p>';?></html>


<html><head><title>Bob's Auto Parts-Order Results</title></head><body><h1>Bob's Auto Parts</h1><h2>Order Results</h2></body><?php$tir = $_POST['tir'];$oil = $_POST['oil'];$tir = '1';$oil = "a";echo '<p> Your order is as follows: </p>';echo $tir . 'tires <br>';echo "$oil oil of<br>";//双引号中,变量名称被变量值所替代,单引号中变量名称或其他文本会不经修改发送给服务器?></html>


<html><head><title>Bob's Auto Parts-Order Results</title></head><body><?phpEcho "hello world <br>";echo "hello world <br>";EcHo "hello world <br>";$A = 1.1;$a = 2;echo "$A  $a";//用户定义的函数,类,关键词(例如if else echo 等等)大小写不敏感,变量大小写敏感?></body></html>


<html><head><title>Bob's Auto Parts-Order Results</title></head><body><?php//类型转换$total = 0;$totalCnt = (float)$total;echo "$total . $totalCnt <br>";//变量$x = 5;$y = 2;$z = $x + $y;echo $z . '<br>';//可变变量,起别名$ref = total;$$ref = 5.1;echo "$total . $ref <br>";//常量define('MAX_APP_CNT',100);$ref = MAX_APP_CNT;echo MAX_APP_CNT . " $ref <br>";//函数之外声明的只能在函数外访问,函数内声明的只能在函数内访问function Test(){$a = 10;echo "x is: $x <br>";}Test();echo "a is: $a <br>";//函数内访问函数外变量function Test1(){global $x;$x = 10;echo "x is: $x <br>";}Test1();echo "x is: $x <br>";//PHP同时在名为$GLOBALS[index]的数组中存储了所有的全局变量function Test2(){$GLOBALS['x'] = $GLOBALS['y'] + $GLOBALS['y'];}echo "x is: $x <br>";//static 关键词function Tes3(){static $x = 0;echo "$x <br>";$x ++;}Tes3();Tes3();//字符串运算符 . $y = $x . ' ab';$y .= " $x";echo "y is: $y <br>";var_dump($x == $y);//引用$a = 5;$b = $a;//产生副本$c = &$a;echo "$a . $b . $c <br>";?></body></html>



echo 和 print 之间的差异:

  • echo - 能够输出一个以上的字符串
  • print - 只能输出一个字符串,并始终返回 1

echo 比 print 稍快,因为它不返回任何值。


PHP var_dump() 会返回变量的数据类型和值。


如需设置常量,请使用 define() 函数 - 它使用三个参数:

  1. 首个参数定义常量的名称
  2. 第二个参数定义常量的值
  3. 可选的第三个参数规定常量名是否对大小写敏感。默认是 false。

<html>    <head>      <title>Bob's Auto Parts-Order Results</title>  </head>    <body>      <h1>Bob's    Auto           Parts</h1>  <h2>Order Results</h2>    </body>      <?php   /*$fp = fopen("text.txt","ab+");fwrite($fp, "hello");$x = 1;fwrite($fp, $x);$fp = fopen("text.txt","rb+");while (!feof($fp)) {$order = fgets($fp,5); //指定长度减一echo $order."<br>";}fclose($fp);$stu = array("na","wang");$stu["a"] = 1;echo $stu[0] . ", " .$stu["a"] . ", " . count($stu) .".<br>";$ss = array($stu,"hello");echo $ss[0] . ", " .$ss[1] . ", " . count($ss) .".<br>";foreach ($stu as $x => $x_value) {echo "Key = " . $x . ", Val = " . $x_value . "<br>";}foreach ($ss[0] as $x => $x_value) {echo "Key = " . $x . ", Val = " . $x_value . "<br>";}*/require("tut1.php");?>      </html>  


<?php/*//引用传参function Test(&$val){$val = 1;}$x = 2;Test($x);echo $x;*/class ClassName{function __construct(){}public $name;}$a = new ClassName();$a->name = "wang";echo $a->name . "<br>";?>



<?phpclass A{protected function Test(){echo "hello <br>";}public $name;}class B extends A{function __construct(){A::Test();}}$b = new B();$b->name = "wang";echo $b->name . "<br>";?>






0 0
原创粉丝点击