how do i reduce a string length without losing meaning

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

how do i reduce a string length without losing meaning

Post by Kadanis »

hi

as part of an app i'm working on, a code is generated in the form number.number i.e. 5.9 (its not a decimal but a code), the problem is that this could be any 2 numbers for example 19972.198234, and this means the string length increases dramatically over time. What i'm looking for is a way that these numbers could be represented while still minimising the string length. The restriction is that what ever is done to them has to be reversable and the original 2 numbers retrieved.

Just wondered if anyone here had any suggestions/ideas on how i could do this, as i'm floundering a little

all suggestions welcome and i'll answer any questions you have that mind help understand the issue.

the app was written in a mixture of php4 and php5.

oh, the numbers can be encoded before they are put in the format x.y if that helps.

thanks
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Convert them to a higher base.
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Post by Kadanis »

aha. and a little research on bases and i found the php function for it too ;)

thanks for the pointer
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

I'd store the two numbers seperately in int fields in the database, and use CONCAT_WS to stick them together on queries.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Floating point has precision errors when you get out to certain ranges which can cause your numbers to become inaccurate. Stick with strings or just don't keep them together.
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post by kingconnections »

What about explode and then using dechex -- Decimal to hexadecimal?

If there is always a . you could split on it and then store as a hex number.
Post Reply