warning: htmlspecialchars() [function.htmlspecialchars]: Invalid multibyte sequence in argument in /var/www/html/drupal-6.25/includes/bootstrap.inc on line 860.

Comments

argosmm’s picture

Hi
I solved this проблем in
yoursite.com/admin/settings/error-reporting

Put these
Write errors to the log

mattyoung’s picture

The problem is check_plain only handles UTF-8 string, however, check_plain is called with random user entered text and if those text are not UTF-8, we get this error. The cause of my problem is check_plain() is called with some text with chinese characters in it.

Right now I temporary fix this by hacking check_plain:

function check_plain($text) {
  static $php525;

  if (!isset($php525)) {
    $php525 = version_compare(PHP_VERSION, '5.2.5', '>=');
  }
  // We duplicate the preg_match() to validate strings as UTF-8 from
  // drupal_validate_utf8() here. This avoids the overhead of an additional
  // function call, since check_plain() may be called hundreds of times during
  // a request. For PHP 5.2.5+, this check for valid UTF-8 should be handled
  // internally by PHP in htmlspecialchars().
  // @see http://www.php.net/releases/5_2_5.php
  // @todo remove this when support for either IE6 or PHP < 5.2.5 is dropped.

  if ($php525) {
    set_error_handler('mosErrorHandler');
    try {
        $result =  htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
    } catch(ErrorException $e) {
        error_log('==============   The string is: "' . $text . '"');
        error_log($e->getTraceAsString());
    }
    restore_error_handler();
    return $result;
  }
  return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';
}



function mosErrorHandler($errno, $errstr, $errfile, $errline, array $errcontext)
{
    // error was suppressed with the @-operator
    if (0 === error_reporting()) {
        return false;
    }

    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}

droplet’s picture