웹프로그래밍

Global It Leader!!


컴퓨터언어


 
 

PHP 사용자 정의 json_encode함수

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 5,559회 작성일 12-09-19 10:13

본문

제가 가끔 쓰는 방법이긴 한데 검색이 필요치 않는 정보 필드로 테이블을 특별히 늘리지 않는 방향에서

디비에 저장할때 json_encode방법으로 $_POST데이터를 object형식으로 만들어서 content에 넣습니다

$wr_content  = json_encode($_POST);


그리고 write 페이지나 뷰페이지에서는 그걸다시 풀어서 뷰해주죠

$data = json_decode($write['wr_content']);

형식으로요.

최근 호스팅에는 왠만하면 저 함수가 다 존제 하는데 오래된 호스팅의 php구버전에서는 함수가 없는 경우가 있습니다.

그럴때 사용자 정의 함수로 처리해야 하는데 매번 검색해서 php.net에서 찾다가

여기에도 올립니다
[code]
if (!function_exists('json_encode')) {
    function json_encode($data) {
        switch ($type = gettype($data)) {
            case 'NULL':
                return 'null';
            case 'boolean':
                return ($data ? 'true' : 'false');
            case 'integer':
            case 'double':
            case 'float':
                return $data;
            case 'string':
                return '"' . addslashes($data) . '"';
            case 'object':
                $data = get_object_vars($data);
            case 'array':
                $output_index_count = 0;
                $output_indexed = array();
                $output_associative = array();
                foreach ($data as $key => $value) {
                    $output_indexed[] = json_encode($value);
                    $output_associative[] = json_encode($key) . ':' . json_encode($value);
                    if ($output_index_count !== NULL && $output_index_count++ !== $key) {
                        $output_index_count = NULL;
                    }
                }
                if ($output_index_count !== NULL) {
                    return '[' . implode(',', $output_indexed) . ']';
                } else {
                    return '{' . implode(',', $output_associative) . '}';
                }
            default:
                return ''; // Not supported
        }
    }
}

[code]
그조화된 데이터는

http://json.parser.online.fr/

이곳에서 확인해보실수있습니다

댓글목록

등록된 댓글이 없습니다.

전체 441
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
열람중 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5560 09-19
160 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6794 09-17
159 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5887 09-14
158 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6312 08-21
157 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6371 08-21
156 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5383 08-17
155 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5458 08-17
154 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6258 08-16
153 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5437 08-16
152 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12166 05-07
151 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5151 08-10
150 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6362 08-03
149 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5555 08-03
148 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6009 07-30
147 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5417 07-27
146 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7159 07-13
145 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6711 06-13
144 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6464 06-08
143 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6324 04-28
142 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8603 04-24