0

Anyone know of a tool to completely encode a string to URL encoding? Best known example is something to convert space character to %20. I want to do this for every single character. What's a good tool for this (linux)?

thanks everyone for down voting, if i cared what language i would have specified. couldnt find anything useful in the other post linked below so i wrote this. this is good enough for me, might be good enough for you.

#include <stdio.h>
// Treats all args as one big string. Inserts implicit spaces between args.
int main(int argc, char *argv[])
{
    if(argc == 1)
    {
        printf("Need something to encode.");
        return 1;
    }
    int count = 0;
    while(++count < argc)
    {
        char *input = argv[count];
        while(*input != '\0')
        {
            printf("%%%x", *input);
            input++;
        }
        printf("%%20");
    }
    printf("\n");
    return 0;
}
rofl
  • 21
  • 2
  • 1
    Linux doesn't tell us your development environment. What language are you using? – JOTN Nov 17 '10 at 00:26
  • "If I cared what language I would have specified." If you *don't* care, there is no possible answer to your question. – user207421 Nov 17 '10 at 01:09

3 Answers3

2

Take a look at this SO question:

Community
  • 1
  • 1
icyrock.com
  • 27,952
  • 4
  • 66
  • 85
0

Which programming language? You can even do something client-side...

tresstylez
  • 1,809
  • 6
  • 29
  • 41
0

i modified this of the other link

perl -p -e 's/(.)/sprintf("%%%02X", ord($1))/seg'

it works nice enough.. run this.. type in what you want to convert..(or pipe it through) and it'll output everything %encoded

ShoeLace
  • 3,476
  • 2
  • 30
  • 44