完整的URL编码

发布于 2024-10-03 08:39:51 字数 683 浏览 6 评论 0原文

有人知道有一个工具可以将字符串完全编码为 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;
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一抹苦笑 2024-10-10 08:39:51

哪种编程语言?你甚至可以在客户端做一些事情......

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

时光暖心i 2024-10-10 08:39:51

我修改了另一个链接,

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

它工作得很好..
运行这个..输入你想要转换的内容..(或通过管道传递)它会输出所有%编码的内容

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文