• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Could not decode a text frame as UTF-8.

phpjavascriptsocketswebsocket


PHP Snippet 1:

socket_write($socket, encode($answer));
function encode($text) {
    $b1 = 0x80 | (0x1 & 0x0f);
    $length = strlen($text);
    if ($length <= 125)
        $header = pack('CC', $b1, $length);
    elseif($length > 125 && $length < 65536)
        $header = pack('CCn', $b1, 126, $length);
    elseif($length >= 65536)
        $header = pack('CCNN', $b1, 127, $length);
    
    return $header.$text;
}

Related Snippets

PHP: Convert any string to UTF-8 without knowing the original character set, or at least try

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

Laravel Route issues with Route order in web.php

Edit XML in HTML form and submit to self

How to retrieve Active Directory group policy maximum password age using LDAP

Match csv filenames to table names and import

Getting values for an enum?

Laravel phpunit test failing authorization

MySQL upgrade causing unexpected results on simple WHERE clauses

Spam Filter in Contact Form

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

Update Order custom Field value with WooCommerce REST API

Array to string conversion

Store / Website Column in Magento 2 Admin Grid - Custom Module

Woocommerce redirect after add-to-cart error

About Contact Privacy policy Terms and conditions