base64 encode와 serialize를 한번에
배열형태의 리스트를 json말고 base64encode와 serialize로 넣고싶을때 사용하시면됩니다.
넣을때 wv_base64_encode_serialize($data)로 넣고, 풀때 $arr= wv_base64_decode_unserialize($data)로 쓰시면됩니다. 아래 코드는 common.lib.php에 넣어주세요
[code]
if(!function_exists('wv_is_base64_encoded')){
function wv_is_base64_encoded($data){
return base64_encode(base64_decode($data, true)) === $data;
}
}
if(!function_exists('wv_is_serialized')){
function wv_is_serialized( $data, $strict = true ) {
// If it isn't a string, it isn't serialized.
if ( ! is_string( $data ) ) {
return false;
}
$data = trim( $data );
if ( 'N;' === $data ) {
return true;
}
if ( strlen( $data ) < 4 ) {
return false;
}
if ( ':' !== $data[1] ) {
return false;
}
if ( $strict ) {
$lastc = substr( $data, -1 );
if ( ';' !== $lastc && '}' !== $lastc ) {
return false;
}
} else {
$semicolon = strpos( $data, ';' );
$brace = strpos( $data, '}' );
// Either ; or } must exist.
if ( false === $semicolon && false === $brace ) {
return false;
}
// But neither must be in the first X characters.
if ( false !== $semicolon && $semicolon < 3 ) {
return false;
}
if ( false !== $brace && $brace < 4 ) {
return false;
}
}
$token = $data[0];
switch ( $token ) {
case 's':
if ( $strict ) {
if ( '"' !== substr( $data, -2, 1 ) ) {
return false;
}
} elseif ( false === strpos( $data, '"' ) ) {
return false;
}
// Or else fall through.
case 'a':
case 'O':
case 'E':
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
case 'b':
case 'i':
case 'd':
$end = $strict ? '$' : '';
return (bool) preg_match( "/^{$token}:[0-9.E+-]+;$end/", $data );
}
return false;
}
}
if(!function_exists('wv_base64_decode_unserialize')){
function wv_base64_decode_unserialize($data){
if(wv_is_base64_encoded($data)){
$data = base64_decode($data);
}
if(wv_is_serialized($data)){
$data = unserialize($data);
}
return $data;
}
}
if(!function_exists('wv_base64_encode_serialize')){
function wv_base64_encode_serialize($data){
if(!wv_is_serialized($data)){
$data = serialize($data);
}
if(!wv_is_base64_encoded($data)){
$data = base64_encode($data);
}
return $data;
}
}
[/code]
댓글 2개
민트다이어리
5개월 전
감사합니다 ^^
4개월 전
감사합니다.
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4443 | ||
| 2664 |
선택과집중
|
4개월 전 | 584 | |
| 2663 |
|
4개월 전 | 631 | |
| 2662 |
|
4개월 전 | 588 | |
| 2661 |
선택과집중
|
4개월 전 | 516 | |
| 2660 | 4개월 전 | 592 | ||
| 2659 |
Modify
|
4개월 전 | 658 | |
| 2658 |
선택과집중
|
5개월 전 | 418 | |
| 2657 | 5개월 전 | 456 | ||
| 2656 |
|
5개월 전 | 966 | |
| 2655 |
선택과집중
|
5개월 전 | 553 | |
| 2654 | 5개월 전 | 408 | ||
| 2653 |
선택과집중
|
5개월 전 | 595 | |
| 2652 | 5개월 전 | 404 | ||
| 2651 | 5개월 전 | 452 | ||
| 2650 |
선택과집중
|
5개월 전 | 331 | |
| 2649 |
선택과집중
|
5개월 전 | 430 | |
| 2648 | 5개월 전 | 444 | ||
| 2647 |
welcome
|
5개월 전 | 548 | |
| 2646 |
디지털홍익인간
|
5개월 전 | 460 | |
| 2645 | 5개월 전 | 474 | ||
| 2644 |
선택과집중
|
5개월 전 | 518 | |
| 2643 | 5개월 전 | 462 | ||
| 2642 | 5개월 전 | 374 | ||
| 2641 | 5개월 전 | 365 | ||
| 2640 | 6개월 전 | 396 | ||
| 2639 | 6개월 전 | 1368 | ||
| 2638 |
|
6개월 전 | 521 | |
| 2637 |
세르반데스
|
6개월 전 | 408 | |
| 2636 |
선택과집중
|
6개월 전 | 574 | |
| 2635 |
선택과집중
|
6개월 전 | 688 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기