推荐开始结束的方法:
1. <?php echo'if you want to serve XHTML or XML documents, do like this';?>
2. <script language="php">
echo 'some editors (like FrontPage) don\'t
like processing instructions';
</script>
html字符:
define() 定义一个常量
const() 调用一个常量
defined() 检查常量是否被定义
number
number
说明一个参数可以是 integer 或者float。
callback
有些诸如 call_user_function() 或
usort() 的函数接受用户自定义的函数作为一个参数。Callback 函数不仅可以是一个简单的函数,它还可以是一个对象的方法,包括静态类的方法。
一个 PHP 函数用函数名字符串来传递。可以传递任何内置的或者用户自定义的函数,除了 array(),echo(),empty(),eval(),exit(),isset(),list(),print()
和 unset()。
一个对象的方法以数组的形式来传递,数组的下标 0 指明对象名,下标 1 指明方法名。
对于没有实例化为对象的静态类,要传递其方法,将数组 0 下标指明的对象名换成该类的名称即可。
实例:判断是否是闰年
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>少年,挑战下闰年!!!</title>
</head>
<body>
<table width="392" height="101" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#CC0000" bgcolor="#FF6600">
<tr>
<td height="25" colspan="2" align="center">判断指定的年份是否为闰年</td>
</tr>
<tr>
<td width="160" height="30" bgcolor="#99FF00"> 请输入一个4位数的年份,是年份!</td>
<td width="219" bgcolor="#99FF00">
<form name="form1" method="post" action="">
<table width="196" height="29" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="136"><input name="txt_year" type="text" value="" size="20"> </td>
<td width="60"> <input type="submit" name="button" value="计算"></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td height="37" colspan="2" align="center">
<?php
#注意使用双引号
if($_POST["button"]!=""){
$year=$_POST["txt_year"];
$result=(($year%4==0&&$year%100!=0)||($year%400==0))?$year."是闰年":$year."sorry 不是闰年!!";
}
echo $result;
?>
</td>
</tr>
</body>
</html>