Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipelavinz/16f6131e94819f25a9032a721af271f0 to your computer and use it in GitHub Desktop.
Save felipelavinz/16f6131e94819f25a9032a721af271f0 to your computer and use it in GitHub Desktop.
function base64ToBits( $validFor ) {
if ( empty( $validFor ) ) {
return '';
}
$validForBits = '';
$validForArr = str_split( $validFor );
$base64Chars = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
for ( $i = 0; $i < count( $validForArr ); $i++ ) {
$thisChar = $validForArr[ $i ];
$val = array_search( $thisChar, $base64Chars );
$bits = str_pad( decbin( $val ), 6, '0', STR_PAD_LEFT );
$validForBits .= $bits;
}
return $validForBits;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment