Your Guide to base64_encode and base64_decode in PHP (Laravel)

How to use base64_encode base64_decode in php


In this article we will learn how to use base64_encode and base64_decode method in PHP Laravel . Both the methods base64_encode and base64_decode in php return string . Both these methods takes 33% more space than the original string . So let's see how to use these methods .

In this example i am using both these methods base64_encode and base64_decode methods in my Laravel project but you can use on your php code too . 

Both these methods supports on following PHP versions .
  • PHP 4
  • PHP 5
  • PHP 7
  • PHP 8

UserController.php :

public function encodeDecode()
      // Encoding a String

      $string = "Hello World";                          // Hello World

      $encoded_string = base64_encode($string); 
      dd($encoded_string);                              // SGVsbG8gV29ybGQ=
      // Decoding an Encoded string
      $decoded_string = base64_decode($encoded_string);
      dd($decoded_string);                              // Hello World

Previous Post Next Post

Contact Form