You are not logged in.

#1 2008-03-14 04:04:55

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

convert a path into alphanumeric, then back

i'm messing around with a small php script, and i've run into an issue that i didnt think would be a big deal but it's turning out to be a pain in the ass.  i need to convert a full, or relative path into an alphanumeric string, then be able to convert back into the original path when needed. 

the kicker is that i'm trying to avoid as many possible problems as i can.  one problem for instance is i could just convert all special characters into a hardcoded string like "." converts into "somestring_dot". but what if for some godforsaken reason there is a folder called somestring_dot.  that would screw up my entire script. 

my first idea was to encrypt the string with a simple function, then decrypt it when needed, but then i realized that not all servers will have say mcrypt.so enabled, so i'd like to avoid that as well.

any thoughts?

for now, i'm doing a urlencode, followed by two preg_replaces to get rid of % and "." but % and "." are just converted into arbitrary strings which is what i want to avoid.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#2 2008-03-14 06:40:25

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: convert a path into alphanumeric, then back

base64 encode

Offline

#3 2008-03-14 12:32:53

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: convert a path into alphanumeric, then back

thanks! that may be what i end up using. it doesnt increase the string size by much and only has one character(that i've seen so far) that i'll have to preg_replace ( = ). 

anyone else have a suggestion?

Last edited by rson451 (2008-03-14 16:56:48)


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#4 2008-03-14 17:28:13

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: convert a path into alphanumeric, then back

The equals signs are just padding and will only ever appear at the end.  You can strip them after encoding and re-add them before decoding.  Depending on the implementation, you may not even have to re-add them to get correct decoding.

Offline

#5 2008-03-14 17:34:04

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: convert a path into alphanumeric, then back

yeah i tried it out and i've gotta take them off, and i have to re-add them for it to decode properly, but it's working good so far.  thanks.


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

Board footer

Powered by FluxBB