简体   繁体   中英

How to set encoding text to UTF-8 in Ratchet (PHP, WebSocket)?

I have the app based in Ratchet. Script created in UTF-8 encoding.

<?php

namespace MyApp;

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use MyApp\Player;
use MyApp\User;
use MyApp\Computer;
use MyApp\Room;
use MyApp\Utils;
use MyApp\PdoConnection;

class Chat implements MessageComponentInterface {
...

In onMessage I accept message from user

public function onMessage(ConnectionInterface $from, $msg) {

When $msg is english text it's all ok, but if it's russian text for example it's look very bad. I understand that encoding is wrong, but how to set encoding to UTF-8 in WebSocket script?

I've understood. WebSocket and Ratchet works well with encoding. Point is that my console where I start websocket script was in bad encoding, I change that. In addition I use substr and other functions, but it's necessary use mb_* in my case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM