I would like to know if I could save some space by compressing small strings of sentences that I have to use base 62 instead of binary.
$string = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore';
$string = pack("nc*", $string); // Doesn't work
$base62 = gmp_strval(gmp_init($string, 2), 62);
I would assume that base 62 would take less space than the ASCII version of the binary.
No. Without restricting the content, an arbitrary string has 8 bits of data per character, and base62 limits you to slightly under 6 bits per character, so you’ll get an expansion of around 25% by doing this.
You’ll need to use a real compression algorithm (e.g,
deflate) to compress data.