Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- httpd-vhosts.conf
- httpd-default.conf
- httpd-mpm.conf
- jQuery
- epel repository
- Node.js 소스 설치
- python 3.X 소스 설치
- PHP 5.2 .ini
- Node.js apache 연동
- vim color scheme
- PHP 5.2.17 .ini
- CentOS
- httpd-dav.conf
- Mod_Security 룰 셋
- unique_id
- gcc update
- CentOS 6
- CentOS 6.10
- MySQL 5.1.41
- mod_unique_id
- httpd 2.2.32
- node.js
- Repository
- apache 연동
- httpd.conf
- python 3.5.10
- vimrc 옵션
- MySQL
- httpd-autoindex.conf
- httpd-info.conf
Archives
- Today
- Total
곰시기's
[PHP] - JsonEncoder 함수 본문
function fncJsonEnc( $data ) {
/*
* $data : 사용자로 부터 받아오는 변수
* $get_type : $data type 확인
* $key, $k : 배열의 key
* $val, $v : 배열의 value
* $rtn : 반환 값
* $flag : 성공 실패 여부
*/
$get_type = "";
$key = "";
$val = "";
$flag = false;
$rtn = "";
$get_type = strtoupper( gettype( $data ) );
switch( $get_type ) {
case "BOOLEAN" :
return $data ? "true" : "false";
break;
case "INTEGER" :
case "DOUBLE" :
return $data;
break;
case "STRING" :
$data = preg_replace( "/(\n|\r|\n\r|\r\n|\t|\s){2,}/", " ", $data );
return '"'.strtr( $data, array( '\\' => '\\\\', '"' => '\\"' ) ).'"';
break;
case "ARRAY" :
$flag = false;
$key = array_keys( $data );
foreach( $key as $val ) {
if( !is_int( $val ) ) {
$flag = true;
break;
}
}
$arr = array();
foreach( $data as $k => $v ) {
$arr[] = ( $flag ? '"'.strtr( $k, array( '\\' => '\\\\', '"' => '\\"' ) ).'":':'').fncJsonEnc( $v );
}
return $flag ? '{'.join( ',', $arr ).'}' : '['.join( ',', $arr ).']';
break;
default :
return '""';
break;
}
}
출처 - https://taegon.kim/archives/944
** \n이 포함된 문자열에 대해 오류가 생겨 한줄을 추가 함'Web Development > PHP' 카테고리의 다른 글
[PHP] - pdf 속성 추출 (0) | 2021.02.16 |
---|---|
[PHP] - Select Box (0) | 2021.02.16 |
[PHP] - 간단한 iconv 함수 (0) | 2021.02.16 |
[PHP] - 원격지 파일 다운로드 (0) | 2021.02.16 |
[PHP] - 문자열 앞까지 자르기 (0) | 2021.02.16 |
Comments