dtvgo28624 2013-08-24 03:59
浏览 110
已采纳

将UTF-8翻译为GB2312

One of my app has links to Chinese websites. These websites use the GB2312 encoding. Unfortunately the .Net framework on WP7 does not support the GB2312 encoding, so the following function does not work.

private string ToGB2312(string character) {
    byte[] bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(character);
    return '%' + BitConverter.ToString(bytes).Replace('-', '%');
}

Instead I'm going to use a web service to redirect the queries:

1. User clicks a link in my app (法)
2. App opens the browser on mysite.com/redirect?codepoint=%E6%B3%95 
3. mysite.com redirects the user to chinesewebsite.com/page?codepoint=%B7%A8

That's because 法 is %E6%B3%95 in utf-8, and %B7%A8 in GB2312.

My question is, how do I do (3.) in php?

  • 写回答

1条回答 默认 最新

  • douhuan1497 2013-08-24 04:20
    关注

    Don't have a PHP environment now, can't test.

    But I think you need these steps:

    1. $gb = mb_convert_encoding(urldecode($_GET['codepoint']), 'GB2312', 'UTF-8');
    2. $gb_url = urlencode($gb);
    3. Redirect with $gb_url
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么