符合python语言变量命名规则_常用HTML转义字符,html转义符,JavaScript转义符,html转义字符表,HTML语言特殊字符对照表(ISO Latin-1字符集) - 来源:嘻嘻网 1...

编码转换(to Unicode)

(程序代码来源于网络)

Js版

test = "你好abc"

str = ""

for( i=0; i

{

temp = test.charCodeAt(i).toString(16);

str += "\\u"+ new Array(5-String(temp).length).join("0") +temp;

}

document.write (str)

vbs版

Function Unicode(str1)

Dim str,temp

str = ""

For i=1 to len(str1)

temp = Hex(AscW(Mid(str1,i,1)))

If len(temp) < 5 Then temp = right("0000" & temp, 4)

str = str & "\u" & temp

Next

Unicode = str

End Function

Function htmlentities(str)

For i = 1 to Len(str)

char = mid(str, i, 1)

If Ascw(char) > 128 then

htmlentities = htmlentities & "" & Ascw(char) & ";"

Else

htmlentities = htmlentities & char

End if

Next

End Function

coldfusion版

function nochaoscode(str)

{

var new_str = “”;

for(i=1; i lte len(str);i=i+1){

if(asc(mid(str,i,1)) lt 128){

new_str = new_str & mid(str,i,1);

}else{

new_str = new_str & “#” & asc(mid(str,i,1));

}

}

return new_str;

}

附:

在php中我们可以用mbstring的mb_convert_encoding函数实现这个正向及反向的转化。 如:

mb_convert_encoding ("你好", "HTML-ENTITIES", "gb2312"); //输出:你好

mb_convert_encoding ("你好", "gb2312", "HTML-ENTITIES"); //输出:你好

如果需要对整个页面转化,则只需要在php文件的头部加上这三行代码:

mb_internal_encoding("gb2312"); // 这里的gb2312是你网站原来的编码

mb_http_output("HTML-ENTITIES");

ob_start('mb_output_handler');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值