开发者

Possible encoding problem in PHP UDP client

开发者 https://www.devze.com 2023-03-02 04:25 出处:网络
I wasn\'t sure how to title this question. I create a UDP connection using PHP fsockopen(). I then use: fwrite ($this->socket, \"command é\"); but it doesn\'t do anything on the server IF it has a

I wasn't sure how to title this question. I create a UDP connection using PHP fsockopen(). I then use: fwrite ($this->socket, "command é"); but it doesn't do anything on the server IF it has a special character in like the é.

I know the information I have given is vague but I am only looking to see if I should be encoding the informa开发者_C百科tion I send in a certain way to pass it in fwrite?

Thanks.


your question is a bit unclear. You didn't talk about your server's protocol or implementation. And, you admitted that!

You rightfully suspect of your é character being the root cause of your problem. The only thing I could suggest you to check is the required character encoding. By default, if you write a string to a stream, it's encoded using the default system encoding, which may differ (and does differ if you run Windows and Linux) between nodes.

What could be happening is that your server doesn't receive command é but something else. You must make sure that both client and server use the same encoding, ie. UTF8.

I don't know if you have control over your server's source code, but I would suggest on the client side

fwrite($this->socket, utf8_encode("command é"));

And, on the server side, to parse the input with utf8_decode()

0

精彩评论

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

关注公众号