Varghese Akhil
Varghese Akhil

Reputation: 13

Convert string to base32 in PHP

I have to pass username as an unique string to a webservice, and the API is asking for the following.

  1. Unique string has to be converted to BASE16
  2. It is the BASE16 value I have to pass.

I cannot find a way to convert the value to BASE16. PHP does not seem to have a BASE16_ENCODE like it does for BASE64.

Example:

$value = <username as an unique string>;
$base16username = base16_encode('$value'); (< Since Base16_encode does not exist, this is my problem)

Google searches are leading me nowhere, nor is the PHP online manual so I suspect I might be overlooking something obvious. Any suggestions?

Upvotes: 1

Views: 3340

Answers (1)

k0pernikus
k0pernikus

Reputation: 66500

Include the package in your composer.json and use it like so:

$encoded = Base32::encode($string);

Upvotes: 3

Related Questions