php函数中不知道怎么在C中调用? html实体与网页编码
mb_convert_encoding ("你好", "HTML-ENTITIES", "gb2312"); //输出:你好
mb_convert_encoding ("你好", "gb2312", "HTML-ENTITIES"); //输出:你好
上面是php函数,在c/c++中怎么实现这样编码?
20320和22909分别是“你”“好”这2个字的unicode码值。
所以这么做即可:
C/C++ code:
char* ConvertGBKToEncodeStr( const char* strGBK )
{
int len=MultiByteToWideChar(936, 0, strGBK, -1, NULL,0);
int i;
WCHAR * wszUCD = new WCHAR[len+1];
memset(wszUtf8, 0, len * 2 + 2);
MultiByteToWideChar(936, 0, strGBK, -1, wszUCD, len);
char *strEncode = new char[len*8+1];
for (i=0;i<wcslen(wszUCD); i++)
{
sprintf(strEncode+strlen(strEncode), "&#%d;", wczUCD[i]);
}
delete[] wszUCD;
return strEncode;
这个是把"你好" 转为你好
反向更简单,直接提取&#和;之间的数字,赋给wchar_t数组即可。
用iconv
php函数的源码,都是纯C的,可以参考
#include <iomanip>
#include <iostream>
#include <string.h>
#include <iconv.h>
#include <locale.h>
#include <stdlib.h>
//#include <easycics>
#define HG_LA
相关问答:
以前在VC里面建一个工程,都只用一个 .c 文件,昨天在一个工程里用了两个 .c文件了,遇到问题了,请大家指点。比如:
File1.c Fil ......
大家好!我是一位C爱好者,向大家请教下,C程序员可好找工作?公司用C干些什么?
无所谓好不好找工作,一般通信、系统、嵌入式、硬件方面用的多,而且由于C的底层特性,学会后在学其他的会比较容易
不管用什么语 ......
//C 接口
extern "C"
{
TESSDLL_API int __cdecl GetTessText(const char *imagefile, char *text);
}
//我在C#中声明
//调用C DLL 中的函数
[DllImport("OCRapi.dll&quo ......
C盘上多的文件名为:dosh , Recycled ,System Volum information, AUTOEXEC.BAT, BOOT.INT , bootfoot.bin, CONFIG.SYS,IO.SYS, MSDOS.SYS, DETECT.COM ,ntldr, pagefile.sys;
而且每个盘上都有这些文件:RECYCLER ......