Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function urlsafe_base64_encode($string)
- {
- return str_replace(['+','/','='], ['-','_',''], base64_encode($string));
- }
- function urlsafe_base64_decode($string)
- {
- $string = str_replace(['-','_'], ['+','/'], $string);
- $mod4 = strlen($string) % 4;
- if ($mod4) $string .= substr('====', $mod4);
- return base64_decode($string);
- }
- /** test code */
- $text = "Smile for me 😃..";
- $encode = urlsafe_base64_encode($text);
- $decode = urlsafe_base64_decode($encode);
- echo "
- String: $text
- Encoded: $encode
- Decoded: $decode
- ";
- if($text == $decode) echo "Validated." . PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement