开发者

Converting to and from Unicode in PHP

开发者 https://www.devze.com 2022-12-23 21:07 出处:网络
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

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

精彩评论

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

关注公众号