duananyu9231 2013-01-10 13:42
浏览 49
已采纳

wchar_t到PHP UTF8文件

i wrote a php script which recieves http POST packages from a windows-client-software.

the windows client uses the "WinHttpClient" for C++.

the WinHttpClient takes the messages i send as wchar_t.

the problem now is, i recieve the messages on my PHP file, but some signs like the "®" sign are shown as "®".

as far as i know, i cannot change the charset of my client to utf-8 or something like that. but maybe some people here know how to "convert" the wide-chars to an utf8 with which PHP can work fine. Because i have to persist the data into an Database which runs only with utf-8.

I tried it with the following, but it doesnt change it :(

function ewchar_to_utf8($matches) {
    $ewchar = $matches[1];
    $binwchar = hexdec($ewchar);
    $wchar = chr(($binwchar >> 8) & 0xFF) . chr(($binwchar) & 0xFF);
    return iconv("unicodebig", "utf-8", $wchar);
}

function special_unicode_to_utf8($str) {
return preg_replace_callback("/\\\u([[:xdigit:]]{4})/i", "ewchar_to_utf8", $str);
}

maybe you got some ideas :) Thanks

  • 写回答

3条回答 默认 最新

  • doutu6616 2013-01-11 11:53
    关注

    the problem now is, i recieve the messages on my PHP file, but some signs like the "®" sign are shown as "®".

    That means you already have UTF-8... misinterpreted in ISO-8859-1/Windows-1252.

    If it's like this

    <?php
    
    echo $rsymbol; //Comes out as ®
    

    Then all you need to change:

    <?php
    header("Content-Type: text/html; charset=UTF-8");
    echo $rsymbol; //Comes out as ®
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探