mapdev\FacebookMessenger\MessengerUtils::checkStringEncoding PHP Method

checkStringEncoding() public static method

public static checkStringEncoding ( $string, $encoding )
    public static function checkStringEncoding($string, $encoding)
    {
        if (!mb_detect_encoding($string, $encoding, true)) {
            throw CouldNotCreateMessage::incorrectEncoding($encoding);
        }
        return $string;
    }

Usage Example

 public function setGreetingText($text)
 {
     return $this->api->callApi('me/thread_settings', ['setting_type' => 'greeting', 'greeting' => ['text' => MessengerUtils::checkStringEncoding(MessengerUtils::checkStringLength($text, 160), 'UTF-8')]]);
 }