2fd457
2fd457
2fd457
#
2fd457
# strip.php /path/to/file key_name
2fd457
# 
2fd457
# Takes a file as input and a string prefix; reads
2fd457
# the file as a serialized data blob and removes a
2fd457
# key with name key_name from the hash.
2fd457
# Serializes again and writes output to stdout.
2fd457
# 
2fd457
2fd457
$file = $_SERVER['argv'][1];
2fd457
$key = $_SERVER['argv'][2];
2fd457
2fd457
function remove_key($array, $name) {
2fd457
    if (array_key_exists($name, $array)) {
2fd457
        unset($array[$name]);
2fd457
    }
2fd457
2fd457
    return $array;
2fd457
}
2fd457
2fd457
$input = file_get_contents($file);
2fd457
2fd457
# Special case for /etc/pear.conf.
2fd457
if (strncmp($input, "#PEAR_Config 0.9\n", 17) == 0) {
2fd457
    echo substr($input, 0, 17);
2fd457
    $s = substr($input, 17);
2fd457
} else {
2fd457
    $s = $input;
2fd457
}
2fd457
2fd457
echo serialize(remove_key(unserialize($s), $key));
2fd457
2fd457
?>