How to Check If String is Base64 Encoded in PHP?
Nov 05, 2022
Hi Dev,
This article will give you example of How to check if string is base64 encoded in PHP. we will help you to give example of base64_decode in PHP example. you can see check if a string is base64 valid in PHP. you will learn Base64 Encode Php Check With Code Examples. you will do the following things for php in check if string is base64 encoded or not.
Example 1:
index.php
<?php
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
?>
Output:
This is an encoded string
Example 2:
index.php
<?php
$data = 'This is a test';
if (base64_decode($data, true) === false) {
echo 'Not a Base64-encoded string';
} else {
echo 'Yes it is a base64 encoded string';
}
?>
Output:
Yes it is a base64 encoded string
I hope it could help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example