To convert a PHP variable to Base64 String we can make use of base64_encode() function,
Syntax : String base64_encode(String $var);
<?php $data = "This is the text to be converted to Base64 string @ $ % ^ & * #@ %& &* &^( " ; $base64EncodedData = base64_encode($data); echo $base64EncodedData; ?>
Similarly, we can make use of base64_decode() function to decode a Base64 encoded text to plain text,
Syntax : String base64_decode(String $Base64encodedString);
<?php $Base64encodedData = "VGhpcyB0ZXh0IHdhcyBiYXNlNjQgZGVjb2RlZCB1c2luZyBiYXNlNjRfZW5jb2RlKCkgZnVuY3Rpb24=
" ; $plainText = base64_encode($Base64encodedData); echo $plainText; ?>
Code2care'smission is to share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities so that our visitors can leverage this portal to find solutions to their queries without re-inventing the wheel. Technical posts include Learnings, Tutorials, Video Tutorials, Code Snippets, Tips-n-tricks.