Usage of multibyte character encodings (e.g. cyrillic) leads to mistakes:

Warning: htmlspecialchars() [function.htmlspecialchars]: Invalid multibyte sequence in argument in check_plain()
PDOException: in drupal_write_record()

One can solve the problem replacing substr by mb_substr or better (thanks to Viktor) by drupal_substring.


  // Ensure the generated title isn't too long.
  $node->title = substr($node->title, 0, 255);


  // Ensure the generated title isn't too long.
  $node->title = drupal_substr($node->title, 0, 255);
multibyte_substr.patch604 bytesvaplas


Darth_Beholder’s picture

Issue summary:View changes

thank you!

becw’s picture

Status:Patch (to be ported)» Reviewed & tested by the community

I ran into this same issue where drupal_write_record() throws PDOExceptions because of node titles with multibyte unicode characters that were truncated by substr(). The original patch fixes the issue for me.

drasgardian’s picture

Patch fixed the issue here too, thank you! Would love to see this committed.