现在的位置: 首页 > 综合 > 正文

PHP 学习第一日

2017年12月11日 ⁄ 综合 ⁄ 共 2084字 ⁄ 字号 评论关闭

推荐开始结束的方法:

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字符:

<br> 可插入一个简单的换行符。
<br> 标签是空标签(意味着它没有结束标签,因此这是错误的:<br></br>)。在 XHTML 中,把结束标签放在开始标签中,也就是 <br />。
注意:<br> 标签只是简单地开始新的一行,而当浏览器遇到 <p> 标签时,通常会在相邻的段落之间插入一些垂直的间距。
define() 定义一个常量
const() 调用一个常量
defined() 检查常量是否被定义

mixed

mixed 说明一个参数可以接受多种不同的(但并不必须是所有的)类型。

例如 gettype() 可以接受所有的 PHP 类型,str_replace() 可以接受字符串和数组。

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"> &nbsp; <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>

抱歉!评论已关闭.