You are here

function Cleantalk::stringToUTF8 in Anti Spam by CleanTalk 8

Function convert string to UTF8 and removes non UTF8 characters param string param string

Return value

string

1 call to Cleantalk::stringToUTF8()
Cleantalk::createMsg in src/Cleantalk.php
Create msg for cleantalk server

File

src/Cleantalk.php, line 625

Class

Cleantalk
Cleantalk class create request

Namespace

Drupal\cleantalk

Code

function stringToUTF8($str, $data_codepage = null) {
  if (!preg_match('//u', $str) && function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding')) {
    if ($data_codepage !== null) {
      return mb_convert_encoding($str, 'UTF-8', $data_codepage);
    }
    $encoding = mb_detect_encoding($str);
    if ($encoding) {
      return mb_convert_encoding($str, 'UTF-8', $encoding);
    }
  }
  return $str;
}