Skip to content

Instantly share code, notes, and snippets.

@kahagon
Created March 23, 2013 11:50
Show Gist options
  • Select an option

  • Save kahagon/5227430 to your computer and use it in GitHub Desktop.

Select an option

Save kahagon/5227430 to your computer and use it in GitHub Desktop.
<?php
function base64_encode_recursively($target) {
if (is_array($target)) {
foreach ($target as $key => $value) {
$target[$key] = base64_encode_recursively($value);
}
return $target;
} else if (is_object($target)) {
$property_list = get_object_vars($target);
foreach ($property_list as $key => $value) {
$target->{$key} = base64_encode_recursively($value);
}
return $target;
} else if (is_null($target)) {
return null;
} else if (is_string($target)) {
switch (mb_detect_encoding($target)) {
case 'ASCII': case 'UTF-8':
return $target;
default:
return base64_encode($target);
}
} else {
return $target;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment