PHP wrapper functions

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:

<?php

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

?>

Correct:

<?php

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

?>

End of "defgroup php_wrappers".

Functions

NameLocationDescription
drupal_chmodincludes/file.incSet the permissions on a file or directory.
drupal_dirnameincludes/file.incGets the name of the directory from a given path.
drupal_http_build_queryincludes/common.incParse an array into a valid, rawurlencoded query string.
drupal_mkdirincludes/file.incCreates a directory using Drupal's default mode.
drupal_parse_urlincludes/common.incWrapper around parse_url() to parse a system URL string into an associative array, suitable for url().
drupal_realpathincludes/file.incReturns the absolute path of a file or directory
drupal_session_regenerateincludes/session.incCalled when an anonymous user becomes authenticated or vice-versa.
drupal_session_startincludes/session.incForcefully start a session, preserving already set session data.
drupal_set_time_limitincludes/common.incAttempts to set the PHP maximum execution time.
drupal_strlenincludes/unicode.incCount the amount of characters in a UTF-8 string. This is less than or equal to the byte count.
drupal_strtolowerincludes/unicode.incLowercase a UTF-8 string.
drupal_strtoupperincludes/unicode.incUppercase a UTF-8 string.
drupal_substrincludes/unicode.incCut off a piece of a string based on character indices and counts. Follows the same behavior as PHP's own substr() function.
drupal_tempnamincludes/file.incCreates a file with a unique filename in the specified directory.
drupal_ucfirstincludes/unicode.incCapitalize the first letter of a UTF-8 string.
drupal_xml_parser_createincludes/unicode.incPrepare a new XML parser.
php_evalmodules/php/php.moduleEvaluate a string of PHP code.
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.