- base64_decode: documentation ( source)
- ord: documentation ( source)
<?php
// Wrongly-encoded garbage, but base64_decode() will try anyway.
$bad = 'ABC123!@#$%';
$out = base64_decode($bad);
if ($out === FALSE) {
echo 'Failed without true as second parameter.'.PHP_EOL;
} else {
$len = strlen($out);
for ($i = 0;$i < $len;$i++) {
echo ord($out[$i]).' ';
}
echo PHP_EOL;
}
// You need to pass TRUE as a second parameter in order to make it fail loudly
$out2 = base64_decode($bad, TRUE);
if ($out2 === FALSE) {
echo 'Failed with true as second parameter.'.PHP_EOL;
} else {
$len = strlen($out);
for ($i = 0;$i < $len;$i++) {
echo ord($out[$i]).' ';
}
echo PHP_EOL;
}