Detect base64 encoding in PHP?

PHPServer Side ProgrammingProgramming

To detect base64 encoding in PHP, the code is as follows −

Example

 Live Demo

<?php
$value_1 = array();
foreach (str_split('az019AZ~~~!@#$%^*()_+|}?><": Iñtërnâtiônàlizætiøn') as $char) {
   echo ord($char) . "n";
   $value_1[] = ord($char);
}
echo "Max value value_1 = " . max($value_1) . "\n";
$value_2 = array();
echo "nnbase64:n";
foreach (str_split(base64_decode('Not base64 encoded',true)) as $char) {
   echo ord($char) . "n";
   $value_2[] = ord($char);
}
echo "Max value_2 = " . max($value_2) . "\n";
?>

Output

This will produce the following output −

97n122n48n49n57n65n90n126n126n126n33n64n35n36n37n94n42n40n41n95n43n124n125n63n62n60n34n58n32n73n195n177n116n195n171n114n110n195n162n116n105n195n180n110n195n160n108n105n122n195n166n116n105n195n184n110nMax value value_1 = 195 nnbase64:n54n139n91n106n199n186n225n233n220n161n215n157nMax value_2 = 233
raja
Published on 09-Apr-2020 10:49:18
Advertisements