Convert string to base32 php
I have to pass username as an unique string to a webservice, and the API is asking for the following.
I cannot find a way to convert the value to BASE16. PHP does not seem to have a Example:
Google searches are leading me nowhere, nor is the PHP online manual so I suspect I might be overlooking something obvious. Any suggestions? Base32 Encoder/Decoder for PHP according to RFC 4648. InstallationUse composer: composer require christian-riesen/base32 Usage
// Include class or user autoloader
use Base32\Base32;
$string = 'fooba';
// $encoded contains now 'MZXW6YTB'
$encoded = Base32::encode($string);
// $decoded is again 'fooba'
$decoded = Base32::decode($encoded); You can also use the extended hex alphabet by using the AboutInitially created to work with the one time password project, yet it can stand alone just as well as Jordi Boggiano kindly pointed out. It's the only Base32 implementation that passes the test vectors and contains unit tests as well. GoalHave a RFC compliant Base32 encoder and decoder. The implementation could be improved, but for now, it does the job and has unit tests. Ideally, the class can be enhanced while the unit tests keep passing. RequirementsWorks on PHP 7.2 and later, including PHP 8.0. Tests run on PHPUnit 9.5, with PHP 7.3 and later. For PHP 7.2, tests use an older PHPUnit version. AuthorChristian Riesen https://christianriesen.com AcknowledgementsBase32 is mostly based on the work of https://github.com/NTICompass/PHP-Base32 (PHP 4, PHP 5, PHP 7, PHP 8) base_convert — Convert a number between arbitrary bases Descriptionbase_convert(string Warning base_convert() may lose precision on large numbers due to properties related to the internal "double" or "float" type used. Please see the Floating point numbers section in the manual for more specific information and limitations. Parametersnum The number to convert. Any invalid
characters in from_base The base to_base The base to convert Return Values Changelog
ExamplesExample #1 base_convert() example
The above example will output: See Also
PHPCoder at niconet2k dot com ¶ 10 years ago
Anonymous ¶ 3 years ago
JR ¶ 11 years ago
Clifford dot ct at gmail dot com ¶ 10 years ago
intval($tobase) != 10) {
lindsay at bitleap dot com ¶ 17 years ago
Theriault ¶ 12 years ago
AdamJacobMuller at AdamJacobMuller dot com ¶ 18 years ago
cyrilbele at yahoo dot fr ¶ 13 years ago
simon at simonster dot com ¶ 18 years ago
from_base256($string, $to_base = 10) {
fiftytoo at buckeyeexpress dot com ¶ 18 years ago
' bpds ¶ 10 years ago
CJ Dennis ¶ 16 years ago
xdv43 at yandex dot ru ¶ 28 days ago
ardavies at tiscali dot co dot uk ¶ 8 years ago
tika dot pahadi at selu dot edu ¶ 6 years ago
denik dot od at gmail dot com ¶ 9 years ago
ohcc at 163 dot com ¶ 5 years ago
bryan at bryanruiz dot com ¶ 11 years ago
$map = array( Anonymous ¶ 4 years ago
andrew at youritland dot co dot uk ¶ 8 years ago
liams dot test dot acc at gmail dot com ¶ 7 years ago
= range(0, 1); francesco[at]paladinux.net ¶ 12 years ago
Ray Paseur sometimes uses GMail ¶ 15 years ago
$input_arabic_numeral == '') { $input_arabic_numeral = date("Y"); } // DEFAULT OUTPUT: THIS YEAR
Baji dot Panchumarti at gmail dot com ¶ 10 years ago
$_pos++ < $_str_len ) { |