함수 uuid to b64uuid()

함수 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 }}