Sometimes you want to pass a url as a path argument. Drupal explodes urls by slash (/) to get the separate "arguments". Since the passed url probably also contains slashes, this will give erroneous results.
Using the following functions (compress_string and decompress_string) you can safely pass urls now and read them well at the other end.
Example:
return urlsafe_base64_encode(gzcompress($string, 9));
}
function decompress_string($string) {
return gzuncompress(urlsafe_base64_decode($string));
}
function urlsafe_base64_encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return $data;
}
function urlsafe_base64_decode($string) {
$data = str_replace(array('-','_'),array('+','/'),$string);
$mod4 = strlen($data) % 4;
if ($mod4) {
$data .= substr('====', $mod4);
}
return base64_decode($data);
}
Delicious
Digg
