Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | base64_encode() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The base64_encode() function is an inbuilt function in PHP that is used to encode data with MIME base64. MIME (Multipurpose Internet Mail Extensions) base64 is used to encode the string in base64. The base64_encoded data takes 33% more space than the original data. 

Syntax:

string base64_encode( $data )

Parameters: This function accepts single parameter $data which is mandatory. It is used to specify the string encoding. 

Return value: This function returns the encoded string in base64 on success or returns False in case of failure. The below programs illustrate the base64_encode() function in PHP.

Program 1: 

php




<?php
 
// Program to illustrate base64_encode()
// function
$str = 'GeeksforGeeks';
 
echo base64_encode($str);
?>


Output:

R2Vla3Nmb3JHZWVrcw==

Program 2: 

php




<?php
 
// Program to illustrate base64_encode()
// function
$str = 'GFG, A computer Science Portal For Geeks';
echo base64_encode($str). "\n";
 
$str = '';
echo base64_encode($str). "\n";
 
$str = 1;
echo base64_encode($str). "\n";
 
$str = '@#$';
echo base64_encode($str). "\n";
?>


Output:

R0ZHLCBBIGNvbXB1dGVyIFNjaWVuY2UgUG9ydGFsIEZvciBHZWVrcw==

MQ==
QCMk

Reference: http://php.net/manual/en/function.base64-encode.php

My Personal Notes arrow_drop_up
Last Updated : 27 Apr, 2023
Like Article
Save Article
Similar Reads
Related Tutorials