PHP wrapper functions

Same name and namespace in other branches
  1. 7.x includes/ \php_wrappers
  2. 9 core/includes/ \php_wrappers
  3. 8.9.x core/includes/ \php_wrappers
  4. 10 core/includes/ \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.


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


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


core/includes/, line 15


Title Sort descending File name Summary
drupal_register_shutdown_function core/includes/ Registers a function for execution on shutdown.
FileSystemInterface::basename core/lib/Drupal/Core/File/FileSystemInterface.php Gets the filename from a given path.
FileSystemInterface::chmod core/lib/Drupal/Core/File/FileSystemInterface.php Sets the permissions on a file or directory.
FileSystemInterface::dirname core/lib/Drupal/Core/File/FileSystemInterface.php Gets the name of the directory from a given path.
FileSystemInterface::mkdir core/lib/Drupal/Core/File/FileSystemInterface.php Creates a directory, optionally creating missing components in the path.
FileSystemInterface::moveUploadedFile core/lib/Drupal/Core/File/FileSystemInterface.php Moves an uploaded file to a new location.
FileSystemInterface::realpath core/lib/Drupal/Core/File/FileSystemInterface.php Resolves the absolute filepath of a local URI or filepath.
FileSystemInterface::rmdir core/lib/Drupal/Core/File/FileSystemInterface.php Removes a directory.
FileSystemInterface::tempnam core/lib/Drupal/Core/File/FileSystemInterface.php Creates a file with a unique filename in the specified directory.
FileSystemInterface::unlink core/lib/Drupal/Core/File/FileSystemInterface.php Deletes a file.
Unicode::lcfirst core/lib/Drupal/Component/Utility/Unicode.php Converts the first character of a UTF-8 string to lowercase.
Unicode::ucwords core/lib/Drupal/Component/Utility/Unicode.php Capitalizes the first character of each word in a UTF-8 string.
UrlHelper::buildQuery core/lib/Drupal/Component/Utility/UrlHelper.php Parses an array into a valid query string encoded with rawurlencode().
UrlHelper::parse core/lib/Drupal/Component/Utility/UrlHelper.php Parses a URL string into its path, query, and fragment components.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.