PHP Classes
elePHPant
Icontem

Oire Base64: URL safe encoding and decoding of data with Base64

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-04-09 (14 days ago) RSS 2.0 feedStarStarStarStar 64%Total: 93 This week: 8All time: 8,670 This week: 120Up
Version License PHP version Categories
oirebase64 1.0MIT/X Consortium ...5PHP 5, Text processing
Description Author

This class can perform URL safe encoding and decoding of data with Base64.

It can take a string and encode it using Base64 but replaces = with ~ to make the encoded data safe for putting in a URL.

The class can also decodes previously encoded base64 data using this class.

  Performance   Level  
Name: Andre Polykanine A.K.A. ... <contact>
Classes: 2 packages by
Country: Ukraine Ukraine
Age: ???
All time rank: 222335 in Ukraine Ukraine
Week rank: 44 Up1 in Ukraine Ukraine Up

Details

URL-safe Base64 Handling

Build Status MIT License

Encodes data to Base64 URL-safe way and decodes encoded data. Note: This package requires PHP 7.1 or above.

use \Oire\Base64;
$text = "The quick brown fox jumps over the lazy dog";
try {
	$encoded = Base64::encode($text);
} catch(Exception $e) {
	// Handle errors
}
echo $encoded.PHP_EOL;

This will output: VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw

By default, the encode() method truncates padding = signs as PHP?s built-in decoder handles this correctly. However, if the second parameter is given and set to true, = signs will be replaced with tildes (~), i.e.:

try {
	$encoded = Base64::encode($text, true);
} catch(Exception $e) {
	// Handle errors
}
echo $encoded.PHP_EOL;

This will output: VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw~~

To decode the data, simply call decode():

$encoded = "VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw";
try {
	$decoded = Base64::decode($encoded);
} catch(Exception $e) {
	// Handle errors
}
echo $decoded.PHP_EOL;

This will output: The quick brown fox jumps over the lazy dog

Installing

Via Composer:

composer require oire/base64

or manually:

require_once("oire/base64.php");

Running Tests

Run phpunit in the projects directory.

License

Copyright © 2017, Andre Polykanine also known as Menelion Elensúlë. This software is licensed under an MIT license.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file autoload.php Aux. Auxiliary script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file base64.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file Base64Test.php Class Class source

 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:93
This week:8
All time:8,670
This week:120Up
User Ratings User Comments (1)
 All timeMonth
Utility:91%StarStarStarStarStar91%Equal
Consistency:91%StarStarStarStarStar91%Equal
Documentation:91%StarStarStarStarStar91%Equal
Examples:--
Tests:--
Videos:--
Overall:64%StarStarStarStar64%Equal
Rank:8225Up
 
nice
13 days ago (muabshir)
70%StarStarStarStar