"함수 uuid to b64uuid()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 9개는 보이지 않습니다)
6번째 줄: 6번째 줄:
[[category: PHP]]
[[category: PHP]]
{{참고|PHP uuid_to_b64uuid()}}
{{참고|PHP uuid_to_b64uuid()}}
<source lang='php'>
<syntaxhighlight lang='php'>
function uuid_to_b64uuid( $uuid ) {
function uuid_to_b64uuid( $uuid ) {
return substr( base64_encode( hex2bin( str_replace('-', '', $uuid) ) ), 0, 22);
        $b64uuid = substr( base64_encode( hex2bin( str_replace('-', '', $uuid) ) ), 0, 22);
        $b64uuid = str_replace('+','-',$b64uuid);
        return str_replace('/','_',$b64uuid);
}
}
var_dump( uuid_to_b64uuid( '71c8851a-9a55-11e4-8e91-7831c1cda656' ) );
var_dump( uuid_to_b64uuid( '71c8851a-9a55-11e4-8e91-7831c1cda656' ) );
var_dump( uuid_to_b64uuid( '11a38b9a-b3da-360f-9353-a5a725514269' ) );
var_dump( uuid_to_b64uuid( '11a38b9a-b3da-360f-9353-a5a725514269' ) );
20번째 줄: 23번째 줄:
# string(22) "xKdgqNvPUlSg2WpEdL0bYg"
# string(22) "xKdgqNvPUlSg2WpEdL0bYg"
# string(22) "bf8m58R2RIOMLO_jwgelFw"
# string(22) "bf8m58R2RIOMLO_jwgelFw"
</source>
</syntaxhighlight>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
{{참고|Python uuid_to_b64uuid()}}
{{참고|Python uuid_to_b64uuid()}}
<source lang='python'>
<syntaxhighlight lang='python'>
import uuid
import uuid
 
def uuid_to_b64uuid( u ):
def uuid_to_b64uuid( u ):
return uuid.UUID(u).bytes.encode('base64').rstrip('=\n')
return uuid.UUID(u).bytes.encode('base64').rstrip('=\n').replace('+','-').replace('/','_')
 
print( uuid_to_b64uuid( '71c8851a-9a55-11e4-8e91-7831c1cda656' ) )
print( uuid_to_b64uuid( '71c8851a-9a55-11e4-8e91-7831c1cda656' ) )
print( uuid_to_b64uuid( '11a38b9a-b3da-360f-9353-a5a725514269' ) )
print( uuid_to_b64uuid( '11a38b9a-b3da-360f-9353-a5a725514269' ) )
print( uuid_to_b64uuid( '6c18d72a-1b7e-4afa-9bc1-1b1f5d34d7ce' ) )
print( uuid_to_b64uuid( '6c18d72a-1b7e-4afa-9bc1-1b1f5d34d7ce' ) )
print( uuid_to_b64uuid( 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62' ) )
print( uuid_to_b64uuid( 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62' ) )
print( uuid_to_b64uuid( '6dff26e7-c476-4483-8c2c-efe3c207a517' ) )
# cciFGppVEeSOkXgxwc2mVg
# cciFGppVEeSOkXgxwc2mVg
# EaOLmrPaNg+TU6WnJVFCaQ
# EaOLmrPaNg-TU6WnJVFCaQ
# bBjXKht+SvqbwRsfXTTXzg
# bBjXKht-SvqbwRsfXTTXzg
# xKdgqNvPUlSg2WpEdL0bYg
# xKdgqNvPUlSg2WpEdL0bYg
</source>
# bf8m58R2RIOMLO_jwgelFw
</syntaxhighlight>
<syntaxhighlight lang='python'>
import uuid, base64
 
def uuid_to_b64uuid( u ):
return base64.urlsafe_b64encode(uuid.UUID(u).bytes).strip("=")
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[함수 b64uuid_to_uuid()]]
*[[함수 b64uuid_to_uuid()]]
*[[함수 b64uuidgen()]]
*[[함수 urlsafe_b64encode()]]
*[[함수 base64_encode()]]
*[[b64uuid]]
*[[b64uuid]]

2020년 11월 2일 (월) 02:33 기준 최신판

함수 uuid_to_b64uuid()

1 PHP[ | ]

function uuid_to_b64uuid( $uuid ) {
        $b64uuid = substr( base64_encode( hex2bin( str_replace('-', '', $uuid) ) ), 0, 22);
        $b64uuid = str_replace('+','-',$b64uuid);
        return str_replace('/','_',$b64uuid);
}
 
var_dump( uuid_to_b64uuid( '71c8851a-9a55-11e4-8e91-7831c1cda656' ) );
var_dump( uuid_to_b64uuid( '11a38b9a-b3da-360f-9353-a5a725514269' ) );
var_dump( uuid_to_b64uuid( '6c18d72a-1b7e-4afa-9bc1-1b1f5d34d7ce' ) );
var_dump( uuid_to_b64uuid( 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62' ) );
var_dump( uuid_to_b64uuid( '6dff26e7-c476-4483-8c2c-efe3c207a517' ) );
# string(22) "cciFGppVEeSOkXgxwc2mVg"
# string(22) "EaOLmrPaNg-TU6WnJVFCaQ"
# string(22) "bBjXKht-SvqbwRsfXTTXzg"
# string(22) "xKdgqNvPUlSg2WpEdL0bYg"
# string(22) "bf8m58R2RIOMLO_jwgelFw"

2 Python[ | ]

import uuid
 
def uuid_to_b64uuid( u ):
	return uuid.UUID(u).bytes.encode('base64').rstrip('=\n').replace('+','-').replace('/','_')
 
print( uuid_to_b64uuid( '71c8851a-9a55-11e4-8e91-7831c1cda656' ) )
print( uuid_to_b64uuid( '11a38b9a-b3da-360f-9353-a5a725514269' ) )
print( uuid_to_b64uuid( '6c18d72a-1b7e-4afa-9bc1-1b1f5d34d7ce' ) )
print( uuid_to_b64uuid( 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62' ) )
print( uuid_to_b64uuid( '6dff26e7-c476-4483-8c2c-efe3c207a517' ) )
# cciFGppVEeSOkXgxwc2mVg
# EaOLmrPaNg-TU6WnJVFCaQ
# bBjXKht-SvqbwRsfXTTXzg
# xKdgqNvPUlSg2WpEdL0bYg
# bf8m58R2RIOMLO_jwgelFw
import uuid, base64

def uuid_to_b64uuid( u ):
	return base64.urlsafe_b64encode(uuid.UUID(u).bytes).strip("=")

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}