etrader Posted January 25, 2011 Share Posted January 25, 2011 I want to encode a long string, and wish to make it shorter. base64_encode is very handy but it makes the string length longer. Is there an alternative to do the encoding/decoding with shorter encoded string length? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2011 Share Posted January 25, 2011 Assuming there is repetitive data and data patterns, you could compress/uncompress the data using zip or gz compression. If the data is not repetitive or is fairly short, the result will still be longer than the original and you will have also wasted the processing time needed to compress/uncompress the data. What exactly are you trying to accomplish? Quote Link to comment Share on other sites More sharing options...
etrader Posted January 25, 2011 Author Share Posted January 25, 2011 Actually, I want to shorten a string which is incorporated into a url. It makes the url too long. I want to make the string shorter to have a shorter url. Then when going to the url, we can GET and decode the string for further processing. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 25, 2011 Share Posted January 25, 2011 That best way of accomplishing that would be to not pass the information through the URL in the first place. Can you pass this same information between pages using $_SESSION variable(s)? There is no magic in programming. zip/gz compression looks for sequences and patterns in the data and makes a table. It then replaces those patterns in the data with a token/value that represents the corresponding entry in the table. The table and the 'tokenized' data must then be transfered, in binary, which would itself require something like base64 encoding to get it all into a URL. You reverse the process when you uncompress the data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.