You are here

function Cleantalk::stringToUTF8 in Anti Spam by CleanTalk 7

Same name and namespace in other branches
  1. 7.5 src/Cleantalk.php \Cleantalk::stringToUTF8()
  2. 7.2 cleantalk.module \Cleantalk::stringToUTF8()
  3. 7.4 src/Cleantalk.php \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 ./cleantalk.module
Create msg for cleantalk server

File

./cleantalk.module, line 963
Main CleanTalk integration module functions.

Class

Cleantalk
Cleantalk class create request

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