PHP wrapper functions

  1. 7.x drupal/includes/common.inc php_wrappers
  2. 8.x drupal/core/includes/common.inc php_wrappers

Functions that are wrappers or custom implementations of PHP functions.

Certain PHP functions should not be used in Drupal. Instead, Drupal's replacement functions should be used.

For example, for improved or more secure UTF8-handling, or RFC-compliant handling of URLs in Drupal.

For ease of use and memorizing, all these wrapper functions use the same name as the original PHP function, but prefixed with "drupal_". Beware, however, that not all wrapper functions support the same arguments as the original functions.

You should always use these wrapper functions in your code.

Wrong:

  $my_substring = substr($original_string, 0, 5);

Correct:

  $my_substring = drupal_substr($original_string, 0, 5);

Functions

Namesort descending Location Description
drupal_basename drupal/core/includes/file.inc Gets the filename from a given path.
drupal_chmod drupal/core/includes/file.inc Sets the permissions on a file or directory.
drupal_dirname drupal/core/includes/file.inc Gets the name of the directory from a given path.
drupal_mkdir drupal/core/includes/file.inc Creates a directory, optionally creating missing components in the path to the directory.
drupal_move_uploaded_file drupal/core/includes/file.inc Moves an uploaded file to a new location.
drupal_realpath drupal/core/includes/file.inc Resolves the absolute filepath of a local URI or filepath.
drupal_register_shutdown_function drupal/core/includes/bootstrap.inc Registers a function for execution on shutdown.
drupal_rmdir drupal/core/includes/file.inc Removes a directory.
drupal_set_time_limit drupal/core/includes/common.inc Attempts to set the PHP maximum execution time.
drupal_strlen drupal/core/includes/unicode.inc Counts the number of characters in a UTF-8 string.
drupal_strtolower drupal/core/includes/unicode.inc Lowercase a UTF-8 string.
drupal_strtoupper drupal/core/includes/unicode.inc Uppercase a UTF-8 string.
drupal_substr drupal/core/includes/unicode.inc Cuts off a piece of a string based on character indices and counts.
drupal_tempnam drupal/core/includes/file.inc Creates a file with a unique filename in the specified directory.
drupal_ucfirst drupal/core/includes/unicode.inc Capitalizes the first letter of a UTF-8 string.
drupal_unlink drupal/core/includes/file.inc Deletes a file.
drupal_xml_parser_create drupal/core/includes/unicode.inc Prepares a new XML parser.
Unicode::lcfirst drupal/core/lib/Drupal/Component/Utility/Unicode.php Converts the first character of a UTF-8 string to lowercase.
Unicode::ucwords drupal/core/lib/Drupal/Component/Utility/Unicode.php Capitalizes the first character of each word in a UTF-8 string.
UrlHelper::buildQuery drupal/core/lib/Drupal/Component/Utility/UrlHelper.php Parses an array into a valid, rawurlencoded query string.
UrlHelper::parse drupal/core/lib/Drupal/Component/Utility/UrlHelper.php Parses a URL string into its path, query, and fragment components.

File

drupal/core/includes/common.inc, line 36
Common functions that many Drupal modules will need to reference.