如何在 Ratchet (PHP, WebSocket) 中将编码文本设置为 UTF-8?

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

我有基于 Ratchet 的应用程序。以 UTF-8 编码创建的脚本。

<?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 {
...

在 onMessage 中我接受来自用户的消息

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

当 $msg 是英文文本时,一切正常,但如果是俄文文本,则看起来很糟糕。 我知道编码是错误的,但是如何在 WebSocket 脚本中将编码设置为 UTF-8?

我明白了。 WebSocket 和 Ratchet 与编码配合得很好。重点是我启动 websocket 脚本的控制台编码错误,我改变了它。另外我使用了 substr 和其他功能,但在我的情况下必须使用 mb_*。