Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compress string, then uncompress the string?

I'm working with hundreds of thousand line strings right now. Is there anyway I could compress the string to like an MD5 like, then uncompress it?

like image 578
Jake Avatar asked Jun 01 '12 21:06

Jake


1 Answers

Yes you can compress and uncompress strings in PHP (Demo):

$str = 'Hello I am a very very very very long string';
$compressed = gzcompress($str, 9);
$uncompressed = gzuncompress($compressed);

echo $str, "\n";
echo $uncompressed, "\n";
echo base64_encode($compressed), "\n";
echo bin2hex($compressed), "\n";
echo urlencode($compressed), "\n";

However MD5 is not compressing but hashing.

See as well: How to compress/decompress a long query string in PHP?

like image 65
hakre Avatar answered Sep 28 '22 15:09

hakre