完整的URL编码
有人知道有一个工具可以将字符串完全编码为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看这个问题:
Take a look at this SO question:
哪种编程语言?你甚至可以在客户端做一些事情......
Which programming language? You can even do something client-side...
我修改了另一个链接,
它工作得很好..
运行这个..输入你想要转换的内容..(或通过管道传递)它会输出所有%编码的内容
i modified this of the other link
it works nice enough..
run this.. type in what you want to convert..(or pipe it through) and it'll output everything %encoded