Use Drupal Unicode functions for strings
This documentation needs work. See "Help improve this page" in the sidebar.
Note: Changes to Drupal coding standards are proposed and discussed in issues in the Coding Standards project.
If you are writing a module or theme, consider that it may be used on web sites around the world, some of which use languages whose characters are multi-byte Unicode, rather than single-byte ASCII or European formats. Some of the built-in PHP string processing functions do not work correctly on multi-byte text.
For that reason, Drupal provides replacements for PHP's built-in text functions. You should use these replacements when you are programming for Drupal, except where noted. The Coder module can be used to check your module for these replacement functions.
Here are the replacement functions:
- drupal_strlen(): Replaces PHP
strlen()
. Note that if you are using strlen() just to check whether the length of a string is non-zero, it is not necessary to use the Drupal replacement. - drupal_strtolower(): Replaces PHP
strtolower()
. - drupal_strtoupper(): Replaces PHP
strtoupper()
. See also drupal_ucfirst(). - drupal_substr(): Replaces PHP
substr()
. See also truncate_utf8() and drupal_truncate_bytes().
For a complete list of all functions wrapping a regular PHP function in Drupal: PHP wrapper functions
If you are programming with text, you should also read the guide to handling text in a secure fashion.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion