开发者

Converting to and from Unicode in PHP

Hey, I'm using php 5 and need to communicate with another server that r开发者_如何学JAVAuns completely in unicode. I need to convert every string to unicode before sending it over. This seems like an easy task, but I haven't been able to find a way to do it yet. Is there a simple function that returns a unicode string? i.e. convert_to_unicode("the string i'm sending")


You can use the utf8_encode and utf8_decode functions. Also, you may need to go through Multibyte String to deal with specific encoding with those mb functions.


You can use either :

  • utf8_encode / utf8_decode
  • The mb_* Multibyte String functions ; in your case, see mb_convert_encoding
  • iconv and the iconv function.


You can use the function utf8_encode


Ok, iconv worked. The trouble is that this is a windows server, so I had to do it in little-endian. UTF-16LE works. Here's the working code:

iconv("UTF-8", "UTF-16LE", "data to send")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜