PHP学习一


<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>';
?>

<?php
	echo '<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>

<?php
	Echo "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>";
?>





<?php
	class 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>";
?>






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MyObject-C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值