php 学习笔记 2

来源:互联网 发布:seo蜘蛛精有什么用 编辑:程序博客网 时间:2024/05/16 13:45
第六章  正则表达式

6.2.1行定位符(& $)
^表示行的开始  $表示行的结尾
^tm表示匹配以tm开头的字符串
6.2.2 单词界定符(\b,\B)
\b表示 要查找的字符串作为一个完成的单词  而\B相反.
6.2.3 字符类([])
只要需要匹配的字符出现在[]内 即可认为成功
eg: [Tt][Mm] 表示 TM Tm tM tm 都可以匹配成功
此外还有一些预定义字符类
[:digit:]  十进制数字集合  [[:alnum:]]字母和数字的集合
[[:alpha:]] 字母集合    [[:blank:]]空格和制表符
[[:xdigit:]] 十六进制数字   [[:punct:]] 特殊字符集合 包括键盘上所有的特殊字符
[[:print:]]所有可打印字符  [[:space:]]空白字符
[[:upper:]]所有大写字母  [[:所有小写字母:]]
[[:cntrl:]]控制字符

6.2.4选择字符 |
(|)可以匹配任意长度的字符串  eg:TM|tm|Tm|tM

6.2.5 连字符 -
eg: [a-zA-z]

6.2.6排除字符([^])
[^a-zA-Z]匹配不以字母和下划线开头的变量名
6.2.7 限定符 ( ? * + {n,m})
?:匹配前面的字符0次或1次
+:匹配前面的字符1+次
*:匹配前面的字符0+次
{n}匹配前面的字符n次了
{n,}匹配前面的字符最少n次
{n,m}匹配前面的字符最少n次,最多m次.

6.2.8 点号字符(.)
. 可以匹配除换行符外的任意一个字符
6.2.9转义字符 \
比如要匹配127.0.0.1 则需要构造 [0-9]{1,3}(\.[0-9]{1,3}){3}
6.2.10反斜线 \
可以将一些不可打印的字符显示出来
6.2.11 ()
改变限定符的作用范围
6.2.12 反向引用
好复杂.....
6.2.13 模式修饰符
同样复杂....


6.3 POSIX扩展正则表达式函数

6.3.1 ereg() eregi()
bool ereg/eregi( string pattern,string string[,array regs])

6.3.2 ereg_replace() eregi_replace()
string ereg_replace(string pattern,string replaement,string string )

6.3.3 split() spliti() 函数
array split(string pattern,string string[,int limit])
使用表达式pattern来分割string 最多有个limit个元素

6.4 PCRE兼容正则表达式函数

array preg_grep(string patteren,array input)
6.4.2 preg_match() preg_match_all()
preg_match_all(string pattern,string subject[<array matches])

6.4.3 preg_quote(string str[,string delimiter])

6.4.4 preg_replace(mixed pattern,mixed replacement,mixed subject[,int limit])


7 数组
7.2 声明数组
7.3 数组的类型
7.3.1数字索引数组
7.3.2关联数组
7.4 输出数组
echo print_r()
7.5 数组的构造
./1.一维
./2.二维
7.6 数组的遍历
foreach($array as $key=>$value)
{
}


实现多文件上传
index.php


<!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" />
</head>
<body>
<?php
echo "<br>-------------------------------------------------<br><br>";
?>
<form action="index_ok.php" method="post" enctype="multipart/form-data" name="form1">
<tr>
<td width="88" height="30" align="right">内容 1:</td>
<td width="369"><input name="picture[]" type="file" id="picture[]" size="30" ></td>
</tr>
<br />
<tr>
<td height="30" align="right" >内容 5:</td>
<td><input name="picture[]" type="file" id="picture[]" size="30" ></td>
</tr>
<br />
<tr>
<td><input type="image" name="imageField" src="images/02-03(3).jpg" /></td>
</tr>


</form>

<?php


?>

<?php
echo "<br>"."-------------------------------------------------"."<br>";
?>



</body>
</html>


index_ok.php

<!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" />
</head>
<body>
<?php
if(!is_dir("./upfile"))
{
mkdir("./upfile");    
}
array_push($_FILES["picture"]["name"],"");
$array=array_unique($_FILES["picture"]["name"]);
array_pop($array);

for($i=0;$i<count($array);$i++)
{
    $path="upfile/".$_FILES["picture"]["name"][$i];
    if(move_uploaded_file($_FILES["picture"]["tmp_name"][$i],$path))
    {
        $result=true;
        }
        else{$result=false;
        }
    }
    if($result==true)
    {
        echo "文件上传成功";
        echo "<meta http-equiv=\"refresh\" content=\"3;url=index.php\">";
        }
        else
        {
            echo "失败";
        echo "<meta http-equiv=\"refresh\" content=\"3;url=index.php\">";            
            }
?>
</body>
</html>







0 0
原创粉丝点击