PHP program to convert a string into base64

Here, we are going to learn how to convert a string into base64 in PHP?
Submitted by Nidhi, on November 22, 2020 [Last updated : March 14, 2023]

String To Base64 Conversion

Here, we will convert a string into base64 using base64_encode() function.

PHP code to convert a string into base64

The source code to convert the string into base64 is given below. The given program is compiled and executed successfully.

<?php
//PHP program to convert the string into base64.
$text = "www.includehelp.com";
$base64 = base64_encode($text);
printf("Base64: [%s]", $base64);
?>

Output

Base64: [d3d3LmluY2x1ZGVoZWxwLmNvbQ==]

Explanation

Here, we created a local variable $text, which is initialized with "www.includehelp.com". After that, we converted the string to base64 using the base64_encode() function and then printed the base64 value on the webpage on the webpage.

More PHP Programs »



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.