urldecode

  编辑
本词条缺少 名片图,补充相关内容使词条更完整,还能快速升级,赶紧来 编辑吧!
本函数对字符串进行URL解码。例如通过 urlencode编码后的字符串,可通过UrlDecode进行解码。对Url路径加码的函数是UrlEncode 用法相反,和UrlDecode是一致对应的·
中文名
路径解码
外文名
urldecode
字符串进行URL解码
返回值:
已解码的字符串 
函数种类:
编码处理

目录

简介

编辑
对字符串进行URL解码。
返回值:已解码的字符串
函数种类: 编码处理

内容说明

编辑
VC环境实现UrlDecode示例
/*
URLEncode是这样编码的
1。数字和字母不变。
2。空格变为"+"号。
3。其他被编码成"%"加上他们的 ascii十六进制,规律是这样的
比如“啊”字 编码的十六进制是B0A1——>%B0%A1(Note:它是每个 字节前加个%)。
*/
#include <iostream>
#include <string>
#include <fstream>
#include <ctype.h>
#include <stdlib.h>
using namespace std;
typedef unsigned char BYTE;
inline BYTE toHex(const BYTE &x)
{
return x > 9 ? x + 55: x + 48;
}
string urlEncoding( string &sIn )
{
cout << " size: " << sIn.size() << endl;
string sOut;
for( int ix = 0; ix < sIn.size(); ix++ )
{
BYTE buf[4];
memset( buf, 0, 4 );
if( isalnum( (BYTE)sIn[ix] ) )
{
buf[0] = sIn[ix];
}
else if ( isspace( (BYTE)sIn[ix] ) )
{
buf[0] = '+';
}
else
{
buf[0] = '%';
buf[1] = toHex( (BYTE)sIn[ix] >> 4 );
buf[2] = toHex( (BYTE)sIn[ix] % 16);
}
sOut += (char *)buf;
}
return sOut;
}
int main(int argc, char *argv[])
{
string src;
ifstream inFile( "in.txt" );
if( !inFile )
{
cout << "not in.txt to read" << endl;
system("PAUSE");
return -1;
}
inFile >> src;
string sOut = urlEncoding( src );
cout << sOut << endl;
system("PAUSE");
return 0;
}
PHP urldecode示例
$str1= urlencode("百度"); //$str1的值是%B0%D9%B6%C8
$str2=urldecode($str1); //$str2的值就是“百度”