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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
■ 에러리포팅
 
ini_set("display_errors",1); //php 에러 리포팅
 
--------------------------------------------------------------------------------------------------------
 
■ 스트링 컷
 
$title = mb_strimwidth(htmlspecialchars($row['board_title']), '0', '40', '..', 'utf-8');
 
--------------------------------------------------------------------------------------------------------
 
■ 매칭
 
preg_match('/(android|Android|iphone)/i', $_SERVER['HTTP_USER_AGENT'])
 
--------------------------------------------------------------------------------------------------------
 
■ 이전글, 다음글
 
/*이전글*/
 
$prev = mysql_fetch_array(mysql_query("SELECT MAX(idx) as idx FROM k_board WHERE idx < '".$idx."' and m_idx = '".$m_idx."' "));
/*다음글*/
$next = mysql_fetch_array(mysql_query("SELECT MIN(idx) as idx FROM k_board WHERE idx > '".$idx."' and m_idx = '".$m_idx."' "));
 
--------------------------------------------------------------------------------------------------------
 
■ 로그파일 생성
 
function addLog($func) //로그파일생성
 
{
 
$content = "";
 
$file = 'log.txt';
 
 
 
if($fp = @fopen("log.txt",r))
 
{
 
$content = fread($fp,filesize($file));
 
fclose($fp);
 
}
 
 
 
$content.= "\n".$_SESSION['memb_id']." : ".$func." : ".date("Y-m-d H:i:s",time());
 
 
 
$fp = fopen("log.txt","w+");
 
fwrite($fp,$content);
 
fclose($fp);
 
}
 
--------------------------------------------------------------------------------------------------------
 
■ 파일업로드
 
if($_FILES[B_FILE][name])
 
{
 
$upload_dir = './upload/';
 
$file_name = time()."_".$_FILES[B_FILE][name];
 
$upload_file = $upload_dir.time().$file_name;
 
 
 
move_uploaded_file($_FILES[B_FILE][tmp_name], $upload_file);
 
}
 
--------------------------------------------------------------------------------------------------------
 
■ 제이슨 데이터 인코딩
 
function json_encode2($data)
 
{
 
switch (gettype($data)) 
 
{
 
case 'boolean':
 
return $data?'true':'false';
 
case 'integer':
 
case 'double':
 
return $data;
 
case 'string':
 
return '"'.strtr($data, array('\\'=>'\\\\','"'=>'\\"')).'"';
 
case 'array':
 
$rel = false; // relative array?
 
$key = array_keys($data);
 
foreach ($key as $v)
 
{
 
if (!is_int($v)) 
 
{
 
$rel = true;
 
break;
 
}
 
}
 
$arr = array();
 
 
 
foreach ($data as $k=>$v) 
 
{
 
$arr[] = ($rel?'"'.strtr($k,array('\\'=>'\\\\','"'=>'\\"')).'":':'').json_encode2($v);
 
}
 
 
 
return $rel?'{'.join(',', $arr).'}':'['.join(',', $arr).']';
 
default:
 
 
 
return '""';
 
}
 
}
 
---------------------------------------------------------------------------------------------------------
 
■ PHP DB연결
 
$connect = mysql_connect('localhost','root','apmsetup');
 
$db_selected = mysql_select_db('kboard', $connect);
 
mysql_query("set names utf8"); // MySQL: utf-8 전용 서버환경에서 한글 깨질때 이 코드를 적용할것
 
---------------------------------------------------------------------------------------------------------
 
■ PHP 시간 계산
 
strtotime($c_date) - (3600*48) //48시간 전
 
---------------------------------------------------------------------------------------------------------
 
■ 역슬러쉬
 
$result3=stripslashes($result2);  // 역슬러쉬를 제거해준다.
 
$str=addslashes($str); // 역슬러쉬를 생성한다.
cs

+ Recent posts