Skip navigation
Help

PHP wrapper functions

  1. drupal
    1. 7 drupal/includes/common.inc

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 & methods

NameDescription
drupal_chmodSet the permissions on a file or directory.
drupal_dirnameGets the name of the directory from a given path.
drupal_http_build_queryParse an array into a valid, rawurlencoded query string.
drupal_json_decodeConverts an HTML-safe JSON string into its PHP equivalent.
drupal_json_encodeConverts a PHP variable into its JavaScript equivalent.
drupal_mkdirCreates a directory using Drupal's default mode.
drupal_parse_urlWrapper around parse_url() to parse a system URL string into an associative array, suitable for url().
drupal_realpathReturns the absolute path of a file or directory
drupal_register_shutdown_functionRegister a function for execution on shutdown.
drupal_rmdirRemove a directory.
drupal_session_regenerateCalled when an anonymous user becomes authenticated or vice-versa.
drupal_session_startForcefully starts a session, preserving already set session data.
drupal_set_time_limitAttempts to set the PHP maximum execution time.
drupal_strlenCount the amount of characters in a UTF-8 string. This is less than or equal to the byte count.
drupal_strtolowerLowercase a UTF-8 string.
drupal_strtoupperUppercase a UTF-8 string.
drupal_substrCut off a piece of a string based on character indices and counts. Follows the same behavior as PHP's own substr() function.
drupal_tempnamCreates a file with a unique filename in the specified directory.
drupal_ucfirstCapitalize the first letter of a UTF-8 string.
drupal_unlinkDeletes a file.
drupal_xml_parser_createPrepare a new XML parser.
php_evalEvaluate a string of PHP code.

File

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