1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
<?php //定义常量 define( "HOST" , "127.0.0.1" );
define( "USER" , "root" );
define( "PWD" , "" );<br>
$conn = "" ;
function
get_conn(){
global
$conn ;
$conn
= mysql_connect(HOST,USER,PWD) or
die (mysql_error());
mysql_select_db( "bbs" , $conn );
mysql_query( "set names ‘utf8‘" );
} function
query( $sql ){
$result
= mysql_query( $sql );
<span style= "background-color: rgb(136, 136, 136);" > //声明一个空的数组</span>
$r
= array ();
while ( $row =mysql_fetch_array( $result )){
<span style= "background-color: rgb(136, 136, 136);" > //每次循环,就把$row传给$r,这样,$r就成了一个自动编号的2维数组</span>
$r [] = $row ;
}
return
$r ;
} //插入方法 function
insert( $sql ){
$result
= mysql_query( $sql );
return
$result ;
} function
insert2( $table , $column , $value ){
$sql
= "insert into $table($column) values($value)" ;
$result
= mysql_query( $sql );
return
$result ;
} function
close(){
global
$conn ;
mysql_close( $conn );
} ?> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<?php function
test1( $str1 = "" , $str2 = array ()){
<span style= "background-color: rgb(136, 136, 136);" > //把数组分割成字符串 implode
//下个这个方法的意思是:$str2应该是个数组
//然后把这个数组按照逗号来分割组成一个新的字符串</span>
$s1
=<span style= "color: rgb(255, 0, 0);" > implode</span>( "," , $str2 );
// echo $s1; <span style= "background-color: rgb(136, 136, 136);" > //把字符串分割成数组 explode
//这个函数的意思就是:首先$str1是一个字符串,这个字符串是按照一个规格组装出来的
//这个规格就是必须符合前面第一个参数的样式</span>
$s2
=<span style= "color: rgb(255, 0, 0);" > explode </span>( "-" , $str1 );
print_r( $s2 );
} <span style= "background-color: rgb(136, 136, 136);" > //函数的默认值</span>
function
test2( $db = "bbs" ){
$conn
= mysql_connect(HOST,USER,PWD) or
die (mysql_error());
mysql_select_db( $db , $conn );
mysql_query( "set names ‘utf8‘" );
} function
test3( $str = "hello world" ){
echo
$str ;
} function
formatDateTime( $date ){
$arr
=<span style= "color: rgb(255, 0, 0);" > explode </span>( "-" , $date );
$str
= <span style= "color: rgb(255, 0, 0);" >vsprintf</span>( "%04d-%02d-%02d" , $arr );
return
$str ;
} <span style= "background-color: rgb(136, 136, 136);" >
//获取函数全部参数 //获取传过来的所有参数</span> function
test4(){
<span style= "background-color: rgb(136, 136, 136);" > //获取传过来参数的数量</span>
$num
= <span style= "color: rgb(255, 0, 0);" >func_num_args</span>();
<span style= "background-color: rgb(136, 136, 136);" > //获取所有传入的参数,返回的是一个数组</span>
$arr
= <span style= "color: rgb(255, 0, 0);" >func_get_args</span>();
var_dump( $arr );
} function
mysql_ping(){
<span style= "background-color: rgb(136, 136, 136);" > //获取传入的所有参数的数组</span>
$arr
=<span style= "color: rgb(255, 0, 0);" > func_get_args</span>();
<span style= "background-color: rgb(136, 136, 136);" > //获取第一个参数,在我们这个列子里面,第一个参数其实就是sql语句</span>
$sql
= $arr [0];
<span style= "background-color: rgb(136, 136, 136);" > //传入的sql语句,其实开始是用?替代的变量的位置
//这里需要将变量转化为可以替换格式化字符串的‘%s‘这样的符号</span>
$sql
=<span style= "color: rgb(255, 0, 0);" > str_replace </span>( "?" , "‘%s‘" , $sql );
<span style= "background-color: rgb(136, 136, 136);" > //array_shift,是将数组最开始的元素移出。返回移出的值,然后数组剩下其余的部分</span>
$values
= <span style= "color: rgb(255, 0, 0);" > array_shift </span>( $arr );
$sql
=<span style= "color: rgb(255, 0, 0);" > vsprintf</span>( $sql , $arr );
echo
$sql ;
} ?> |
验证码图片里的点点与线线
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
imagefill( $img ,0,0, $background );
<span style= "background-color: rgb(136, 136, 136);" > //字体颜色</span>
$color
= <span style= "color: rgb(255, 0, 0);" >imagecolorallocate</span>( $img ,rand(0,255),rand(0,255),rand(0,255));
$color1
= <span style= "color: rgb(255, 0, 0);" >imagecolorallocate</span>( $img ,rand(0,255),rand(0,255),rand(0,255));
<span style= "background-color: rgb(136, 136, 136);" > //生成干扰线</span>
$lineX1
= rand(1,200);
$lineX2
= rand(30,50);
for ( $i
= 0; $i <3; $i ++){
$lineY1
= rand(3,300);
$lineY2
= rand(13,50);
<span style= "color: rgb(255, 0, 0);" > imageline</span>( $img , $lineX1 , $lineX2 , $lineY1 , $lineY2 , $color1 );
$lineX1
+= rand(30,95);
$lineX2
+= rand(100,200);
}
<span style= "background-color: rgb(136, 136, 136);" > //在图片上生成点点</span>
for ( $i =0; $i <50; $i ++){
$color3
= <span style= "color: rgb(255, 0, 0);" >imagecolorallocate</span>( $img ,rand(0,255),rand(0,255),rand(0,255));
<span style= "color: rgb(255, 0, 0);" >imagesetpixel</span>( $img ,rand(2,300),rand(3,50), $color3 );
}
<span style= "background-color: rgb(136, 136, 136);" > //图片上生成文字
//使图片上的文字层次不齐</span>
$postX
= rand(6,45);
for ( $i =0; $i <4; $i ++){
$postY
= rand(2,15);
<span style= "color: rgb(255, 0, 0);" > imagestring</span>( $img ,rand(2,6), $postX , $postY , substr ( $rand , $i ,1), $color );
$postX
+= rand(8,20);
}
|