wrote this once to strip dots and slahses from user-inputted paths. Changed not_allowed array for your needs
function clean_path($path)
{
$i = 0;
$not_allowed = array(
0 => "0"
);
if(in_array($path{0}, $not_allowed))
{
$path = substr($path, 1);
$i = 1;
}
$length = strlen($path)-1;
if(in_array($path{$length}, $not_allowed)) // remove if 0-es at the end are allowed
{
echo 1;
$path = substr($path, 0, $length-1);
$i = 1;
}
if($i == 1)
{
$path = clean_path($path);
}
return $path;
}