5

When I'm searching my site, I get this error:

Warning: htmlspecialchars(): Invalid multibyte sequence in argument in check_plain() (line 1476 of /var/www/includes/bootstrap.inc).

What does it mean and how can I correct it?

EDIT: The problem disappeared after migrating to webhosting server, so the problem should be something in settings in my local computer.

  • WHat version of Drupal and what version of PHP? – mpdonadio Jun 18 '11 at 11:32
  • What charset are you using, and have you looked at headers to see if everything is working as expected, and that everything is being done with a consistent charset? – mpdonadio Jun 18 '11 at 11:59
  • @MPD PHP 5.3.2, Drupal 7 – xralf Jun 19 '11 at 9:02
  • @MPD Where can I see what charset I'm using and look at the headers? – xralf Jun 19 '11 at 9:04
  • Use Firefox. You should see then in Right-Click, Page Info or use the Live HTTP Headers plugin to watch the whole transfer, including redirects. – mpdonadio Jun 19 '11 at 11:58
1

The problem is caused by the search module. It does not handle multibyte characters correctly. Watch this thread: http://drupal.org/node/987472 Fixing the search module fixed the problem for me. However wait for an authorized patch.

Your webhoster doesn't show the error not because it is not there, but because they have a better production settings. The error can be easily suppressed using PHP settings.

  • OK I'll wait for authorized patch and believe it's the bug and accept your answer (if somebody won't persuade us that the problem is elsewhere) – xralf Sep 11 '11 at 9:53
2

Try adding some instrumentation by replacing the check_plain function with this version:

function check_plain($text) {
  $plain = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  if (empty($plain) && !empty($text)) {
    dpm($text);
    ddebug_backtrace();
  }
}

You will need to have the devel module enabled. The next time the error is triggered, the offending text will be displayed along with a backtrace that shows what function triggered the error. With that info, you can search your code and database for the offending text and remove it.

  • Can I log this information to some file without installing devel module? – xralf Jun 22 '11 at 13:46
  • you can replace the debug statements with native PHP:error_log($text, 3, '/tmp/text.log'); error_log(var_dump(debug_backtrace()), 3, '/tmp/trace.log'); the devel output is much easier to understand, though. – Dylan Tack Jun 22 '11 at 17:33
  • I tried it but with this replacement the web does not work. It lost all styles I can't see many things and I can't click on nothing (it doesn't react). – xralf Jun 22 '11 at 18:22
  • The problem disappeared after migrating to webhosting server, so the problem should be something in settings in my local computer. – xralf Jul 10 '11 at 18:36
1

This has occured to me because I had left some Unicode (é, ó...) in a template file or a module, be sure to check this. Generally you need to use the t() function and then translate your string in the translate interface admin/build/translate.
If you can't do this, you can use utf8_encode('é') but that's not very pretty.

  • I'm using only english characters in coding. – xralf Jun 12 '11 at 17:32
  • May be you are passing an empty string. – Sivaji Jun 18 '11 at 12:26
1

Wild guess here, but I suspect something isn't UTF-8 clean.

check_plain is hardcoded for UTF-8. I suspect that you are some part of your transfer is in ISO-8859-1.

Watch the transfer with Live HTTP Headers. If you see anything other than UTF-8 in requests or responses, then you need to tweak some non-Drupal settings.

  • Live HTTP Headers shows Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 but I have no idea what to change in Drupal settings. – xralf Jun 20 '11 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.