Code For Colorful Life
正则表达式小结
###分隔符
当使用 PCRE 函数的时候,模式需要由分隔符闭合包裹。分隔符可以使任意非字母数字、非反斜线、非空白字符。经常使用的分隔符是正斜线(/)、hash符号(#) 以及取反符号(~)。
###元字符
元字符是正则表达式中具有特殊意义的专用字符,用来规定其前导字符在目标对象中的出现模式.
共有两种不同的元字符:一种是可以在模式中方括号外任何地方使用的,另外一种 是需要在方括号内使用的。(元字符列表)[http://www.php.net/manual/zh/regexp.reference.meta.php]
Read more...
2013-10-03 PHP应用
Ajax提交表单
主要使用了jQuery ajax - serialize()
方法.
The .serialize() method creates a text string in standard URL-encoded notation.
It can act on a jQuery object that has selected individual form controls, such as <input>
, <textarea>
, and <select>
: $( "input, textarea, select" ).serialize();
html代码:
Read more...
2013-09-29 PHP练手
多个文件上传
html代码如下,有两点需要注意的:一是设置form的enctype属性,二是使用post方法
1
2
3
4
5
6
7
8
9
10
11
12
13
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form action="test.php" method="post" enctype="multipart/form-data">
<input type="file" name="userfile1">
<input type="file" name="userfile2">
<input type="file" name="userfile3">
<input type="submit">
</form>
</body>
</html>
Read more...
2013-09-25 PHP练手
PHP中比较少用但很有用的几个函数
###函数接收任意数量的参数
1
2
3
4
5
6
7
8
9
10
11
<?php
function funtest() {
$args = func_get_args();
foreach ( $args as $k => $v ) {
echo 'arg'.($k+1).': '.$v.'<br />';
}
}
funtest();
funtest( 'hello' );
funtest( 'hello', 'world', 'next' );
?>
Read more...
2013-09-23 PHP练手
递归遍历目录
###方法一
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<meta charset="utf-8">
<?php
function showDir($dir)
{
$r = array();
foreach (scandir($dir) as $key => $value) {// scandir()列出指定路径中的文件和目录
if ($value === '.' || $value === '..' ) {
continue;
}
if (is_dir($dir.'/'.$value)) {
$r[$dir.'/'.$value] = showDir($dir.'/'.$value);
}
}
return $r;
}
var_dump(showDir('.'));
?>
Read more...
2013-09-22 PHP练手