- 论坛徽章:
- 0
|
char* htmldecode(char *p, int *str_len, char *buf)
{
register i=0, len=0;
char *q;
char tmp[8192];
unsigned int c;
bzero(buf, sizeof(buf));
bzero(tmp, sizeof(tmp));
strncpy(tmp, p, *str_len);
(*str_len)=0;
p=tmp;
while(*(p+i))
{
if ((*p=*(p+i)) == '&' && *(p+i+1) == '#' )
{
q=p+i;
while(*q != ';') q++;
len=q-p-i;
c=(atoi(p+i+2));
memcpy(buf, &c, 2);
buf+=2;
p++;
(*str_len)+=2;
i=q-p;
}else{
c=(*p);
memcpy(buf, &c, 2);
buf+=2;
(*str_len)+=2;
}
p++;
}
*p='\0';
}
int main(){
char a[]="aa我@.doc@sadf@";
int len;
int i;
unsigned char *str = (unsigned char *) malloc (strlen(a)*2);
len=strlen(a);
htmldecode(a, &len, str);
printf("%s\n", a);
for(i=0; i<len; i++)
printf("%c", str[i]);
free(str);
return 0;
} |
|