You are here

function drupal_convert_to_utf8 in Drupal 6

Same name and namespace in other branches
  1. 4 includes/unicode.inc \drupal_convert_to_utf8()
  2. 5 includes/unicode.inc \drupal_convert_to_utf8()
  3. 7 includes/unicode.inc \drupal_convert_to_utf8()

Convert data to UTF-8

Requires the iconv, GNU recode or mbstring PHP extension.

Parameters

$data: The data to be converted.

$encoding: The encoding that the data is in

Return value

Converted data or FALSE.

2 calls to drupal_convert_to_utf8()
drupal_xml_parser_create in includes/unicode.inc
Prepare a new XML parser.
_mime_header_decode in includes/unicode.inc
Helper function to mime_header_decode

File

includes/unicode.inc, line 172

Code

function drupal_convert_to_utf8($data, $encoding) {
  if (function_exists('iconv')) {
    $out = @iconv($encoding, 'utf-8', $data);
  }
  else {
    if (function_exists('mb_convert_encoding')) {
      $out = @mb_convert_encoding($data, 'utf-8', $encoding);
    }
    else {
      if (function_exists('recode_string')) {
        $out = @recode_string($encoding . '..utf-8', $data);
      }
      else {
        watchdog('php', 'Unsupported encoding %s. Please install iconv, GNU recode or mbstring for PHP.', array(
          '%s' => $encoding,
        ), WATCHDOG_ERROR);
        return FALSE;
      }
    }
  }
  return $out;
}