You are here

public function Cleantalk::stringToUTF8 in Anti Spam by CleanTalk 7.4

Same name and namespace in other branches
  1. 7.5 src/Cleantalk.php \Cleantalk::stringToUTF8()
  2. 7 cleantalk.module \Cleantalk::stringToUTF8()
  3. 7.2 cleantalk.module \Cleantalk::stringToUTF8()

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 660

Class

Cleantalk
Cleantalk Base class

Code

public 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;
}