PHP Base64 encoding decoding a variable

To convert a PHP variable to Base64 String we can make use of base64_encode() function,

Syntax : String base64_encode(String $var);

Code Examples :

    $data = "This is the text to be converted to Base64 string @ $ % ^ & * #@ %& &* &^( " ;

    $base64EncodedData = base64_encode($data);
    echo $base64EncodedData;


Output : VGhpcyBpcyB0aGUgdGV4dCB0byBiZSBjb252ZXJ0ZWQgdG8gQmFzZTY0IHN0cmluZyBAICQgJSBeICYgKiAjQCAlJiAmKiAmXigg

Recent Posts:

Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.