_unicode_check

Versions
4.7
_unicode_check($errors = false)
5 – 7
_unicode_check()

Perform checks about Unicode support in PHP, and set the right settings if needed.

Because Drupal needs to be able to handle text in various encodings, we do not support mbstring function overloading. HTTP input/output conversion must be disabled for similar reasons.

Parameters

$errors Whether to report any fatal errors with form_set_error().

▾ 2 functions call _unicode_check()

unicode_check in includes/unicode.inc
Wrapper around _unicode_check().
unicode_settings in includes/unicode.inc
Return the required Unicode status and errors for admin/settings.

Code

includes/unicode.inc, line 25

<?php
function _unicode_check($errors = false) {
  // Set the standard C locale to ensure consistent, ASCII-only string handling.
  setlocale(LC_CTYPE, 'C');

  // Check for outdated PCRE library
  // Note: we check if U+E2 is in the range U+E0 - U+E1. This test returns TRUE on old PCRE versions.
  if (preg_match('/[à-á]/u', 'â')) {
    if ($errors) {
      form_set_error('unicode', t('The PCRE library in your PHP installation is outdated. This will cause problems when handling Unicode text. If you are running PHP 4.3.3 or higher, make sure you are using the PCRE library supplied by PHP. Please refer to the <a href="%url">PHP PCRE documentation</a> for more information.', array('%url' => 'http://www.php.net/pcre')));
    }
    return UNICODE_ERROR;
  }

  // Check for mbstring extension
  if (!function_exists('mb_strlen')) {
    return UNICODE_SINGLEBYTE;
  }

  // Check mbstring configuration
  if (ini_get('mbstring.func_overload') != 0) {
    if ($errors) {
      form_set_error('unicode', t('Multibyte string function overloading in PHP is active and must be disabled. Check the php.ini <em>mbstring.func_overload</em> setting. Please refer to the <a href="%url">PHP mbstring documentation</a> for more information.', array('%url' => 'http://www.php.net/mbstring')));
    }
    return UNICODE_ERROR;
  }
  if (ini_get('mbstring.encoding_translation') != 0) {
    if ($errors) {
      form_set_error('unicode', t('Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.encoding_translation</em> setting. Please refer to the <a href="%url">PHP mbstring documentation</a> for more information.', array('%url' => 'http://www.php.net/mbstring')));
    }
    return UNICODE_ERROR;
  }
  if (ini_get('mbstring.http_input') != 'pass') {
    if ($errors) {
      form_set_error('unicode', t('Multibyte string input conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.http_input</em> setting. Please refer to the <a href="%url">PHP mbstring documentation</a> for more information.', array('%url' => 'http://www.php.net/mbstring')));
    }
    return UNICODE_ERROR;
  }
  if (ini_get('mbstring.http_output') != 'pass') {
    if ($errors) {
      form_set_error('unicode', t('Multibyte string output conversion in PHP is active and must be disabled. Check the php.ini <em>mbstring.http_output</em> setting. Please refer to the <a href="%url">PHP mbstring documentation</a> for more information.', array('%url' => 'http://www.php.net/mbstring')));
    }
    return UNICODE_ERROR;
  }

  // Set appropriate configuration
  mb_internal_encoding('utf-8');
  mb_language('uni');
  return UNICODE_MULTIBYTE;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.