完整的URL编码

时间:2010-11-17 00:20:53

标签: url encoding urlencode

有人知道将字符串完全编码为URL编码的工具吗?最着名的例子是将空格字符转换为%20。我想为每一个角色做这件事。什么是这个(Linux)的好工具?

感谢大家的投票,如果我关心我会指定的语言。在下面链接的其他帖子中找不到任何有用的东西,所以我写了这个。这对我来说已经够好了,对你来说可能还不错。

#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;
}

3 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

哪种编程语言?你甚至可以做客户端......

答案 2 :(得分:0)

我修改了另一个链接

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

它工作得很好.. 运行此..键入你想要转换的..(或管道通过),它将输出所有%编码