2

My client wants to store more than 60 characters length text but I can not use more than 60 characters to store this data, so...

I am looking for a way to reduce/compress a short text (less than 60 characters), I tested gzcompress, gzdeflate, gzencode, bzcompress, base64_encode and bin2hex, but I am getting equal or more characters than the original text.

$char="This is a sample short text";
echo "<div>$char</div>";
echo "<div>It has ".strlen($char)." characters</div>";

$chargz=gzcompress($char,9);
echo "<div>gzcompress has ".strlen($chargz)." characters</div>";

$chargz=gzdeflate($char,9);
echo "<div>gzdeflate has ".strlen($chargz)." characters</div>";

$chargz=gzencode($char,9);
echo "<div>gzencode has ".strlen($chargz)." characters</div>";

$chargz=bzcompress($char,9);
echo "<div>bzcompress has ".strlen($chargz)." characters</div>";

$chargz=base64_encode($char);
echo "<div>base64_encode has ".strlen($chargz)." characters</div>";

$chargz=bin2hex($char);
echo "<div>bin2hex has ".strlen($chargz)." characters</div>";

These are the results:

This is a sample short text
It has 27 characters
gzcompress has 33 characters
gzdeflate has 27 characters
gzencode has 45 characters
bzcompress has 61 characters
base64_encode has 36 characters
bin2hex has 54 characters

As you can see I am not really getting any length reduction, these methods works fine with longer texts, but what about short texts?

How to reduce the lenght of short strings?

stramin
  • 2,183
  • 3
  • 29
  • 58
  • 1
    Related https://stackoverflow.com/questions/1138345/an-efficient-compression-algorithm-for-short-text-strings – u_mulder Oct 08 '19 at 21:20

0 Answers0