Praful Kumar Web page - PHP Function 01

65. get_browser (PHP 4, PHP 5)
get_browser — Tells what the user's browser is capable of
mixed get_browser ( [string $user_agent [, bool $return_array]] )
Attempts to determine the capabilities of the user's browser, by looking up the browser's information in the browscap.ini file.
echo $_SERVER['HTTP_USER_AGENT'] . "nn";
$browser = get_browser(null, true);

66. get_class (PHP 4, PHP 5)
get_class — Returns the name of the class of an object
string get_class ( [object $object] )
Gets the name of the class of the given object.
class foo {
function foo() { // implements some logic
function name() {
echo "My name is " , get_class($this) , "n";
} }
$bar = new foo(); // create an object
echo "Its name is " , get_class($bar) , "n"; // external call
$bar->name(); // internal call

The above example will output:
Its name is foo
My name is foo

67. get_current_user (PHP 4, PHP 5)
get_current_user — Gets the name of the owner of the current PHP script
string get_current_user ( void )
Returns the name of the owner of the current PHP script.

68. getcwd (PHP 4, PHP 5)
getcwd — Gets the current working directory
string getcwd ( void )
Gets the current working directory.

69. getdate (PHP 4, PHP 5)
getdate — Get date/time information
array getdate ( [int $timestamp] )
Returns an associative array containing the date information of the timestamp, or the current local time if no timestamp is given.
$today = getdate();

The above example will output something similar to:
Array([seconds] => 40 [minutes] => 58 [hours] => 21 [mday] => 17 [wday] => 2 [mon] => 6 2019 => 2003 [yday] => 167 [weekday] => Tuesday [month] => June [0] => 1055901520)

70. gettype (PHP 4, PHP 5)
gettype — Get the type of a variable
string gettype ( mixed $var )
Returns the type of the PHP variable var.
Never use gettype() to test for a certain type, since the returned string may be subject to change in a future version. In addition, it is slow too, as it involves string comparison.
Instead, use the is_* functions.

71. gmdate (PHP 4, PHP 5)
gmdate — Format a GMT/UTC date/time
string gmdate ( string $format [, int $timestamp] )
Identical to the date() function except that the time returned is Greenwich Mean Time (GMT).
echo date("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998));
echo gmdate("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998));

72. preg_grep (PHP 4, PHP 5)
preg_grep — Return array entries that match the pattern
array preg_grep ( string $pattern, array $input [, int $flags] )
Returns the array consisting of the elements of the input array that match the given pattern.
// return all array elements
// containing floating point numbers
$fl_array = preg_grep("/^(d+)?.d+$/", $array);

73. preg_match(PHP 4, PHP 5)
preg_match — Perform a regular expression match
int preg_match ( string $pattern, string $subject [, array &$matches [, int $flags [, int $offset]]] )
Searches subject for a match to the regular expression given in pattern.

$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);

The above example will output:
Array( )

while this example
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
will produce

Array( [0] => Array ([0] => def [1] => 0 ))

74. preg_match_all (PHP 4, PHP 5)
preg_match_all — Perform a global regular expression match
int preg_match_all ( string $pattern, string $subject, array &$matches [, int $flags [, int $offset]] )
Searches subject for all matches to the regular expression given in pattern and puts them in matches in the order specified by flags.
After the first match is found, the subsequent searches are continued on from end of the last match.

// The 2 is an example of backreferencing. This tells pcre that
// it must match the second set of parentheses in the regular expression
// itself, which would be the ([w]+) in this case. The extra backslash is
// required because the string is in double quotes.
$html = "bold textclick me";
preg_match_all("/(<([w]+)[^>]*>)(.*)()/", $html, $matches, PREG_SET_ORDER);

foreach ($matches as $val) {
echo "matched: " . $val[0] . "n";
echo "part 1: " . $val[1] . "n";
echo "part 2: " . $val[3] . "n";
echo "part 3: " . $val[4] . "nn";

The above example will output:
matched: bold text
part 1:
part 2: bold text
part 3:

matched: click me
part 1:
part 2: click me
part 3:

75. preg_quote (PHP 4, PHP 5)
preg_quote — Quote regular expression characters
string preg_quote ( string $str [, string $delimiter] )
preg_quote() takes str and puts a backslash in front of every character that is part of the regular expression syntax. This is useful if you have a run-time string that you need to match in some text and the string may contain special regex characters.
The special regular expression characters are: . + * ? [ ^ ] $ ( ) { } = ! < > | :
$keywords = '$40 for a g3/400';
$keywords = preg_quote($keywords, '/');
echo $keywords; // returns $40 for a g3/400

76. preg_replace (PHP 4, PHP 5)
preg_replace — Perform a regular expression search and replace
mixed preg_replace ( mixed $pattern, mixed $replacement, mixed $subject [, int $limit [, int &$count]] )
Searches subject for matches to pattern and replaces them with replacement.
$string = 'The quick brown fox jumped over the lazy dog.';
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $string);

The above example will output:
The bear black slow jumped over the lazy dog.

77. preg_split (PHP 4, PHP 5)
preg_split — Split string by a regular expression
array preg_split ( string $pattern, string $subject [, int $limit [, int $flags]] )
Split the given string by a regular expression.
// split the phrase by any number of commas or space characters,
// which include " ", r, t, n and f
$keywords = preg_split("/[s,]+/", "hypertext language, programming");

78. print_r (PHP 4, PHP 5)
print_r — Prints human-readable information about a variable
mixed print_r ( mixed $expression [, bool $return] )
print_r() displays information about a variable in a way that's readable by humans.
print_r(), var_dump() and var_export() will also show protected and private properties of objects with PHP 5.
Remember that print_r() will move the array pointer to the end. Use reset() to bring it back to beginning.
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
The above example will output:

Array( [a] => apple[b] => banana[c] => Array([0] => x[1] => y[2] => z))

79. rand (PHP 4, PHP 5)
rand — Generate a random integer
int rand ( [int $min, int $max] )
If called without the optional min, max arguments rand() returns a pseudo-random integer between 0 and RAND_MAX. If you want a random number between 5 and 15 (inclusive), for example, use rand (5, 15).
Note: On some platforms (such as Windows) RAND_MAX is only 32768. If you require a range larger than 32768, specifying min and max will allow you to create a range larger than RAND_MAX, or consider using mt_rand() instead.
Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
echo rand() . "n";
echo rand() . "n";
echo rand(5, 15);

The above example will output something similar to:

80. range (PHP 4, PHP 5)
range — Create an array containing a range of elements
array range ( mixed $low, mixed $high [, number $step] )
range() returns an array of elements from low to high, inclusive. If low > high, the sequence will be from high to low.
New parameter: The optional step parameter was added in 5.0.0.
If a step value is given, it will be used as the increment between elements in the sequence. step should be given as a positive number. If not specified, step will default to 1.

81. rename (PHP 4, PHP 5, PECL zip:1.1.0-1.4.1)
rename — Renames a file or directory
bool rename ( string $oldname, string $newname [, resource $context] )
Attempts to rename oldname to newname.
rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");

82. rename_function (PECL apd:0.2-1.0.1)
rename_function — Renames orig_name to new_name in the global function table
bool rename_function ( string $original_name, string $new_name )
Renames a orig_name to new_name in the global function table. Useful for temporarily overriding built-in functions.
rename_function('mysql_connect', 'debug_mysql_connect' );

82 A. require()
The require() statement includes and evaluates the specific file.
require() includes and evaluates a specific file. Detailed information on how this inclusion works is described in the documentation for include().
require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well.

require 'prepend.php';
require $somefile;
require ('somefile.txt');

83. require_once()
The require_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the require() statement, with the only difference being that if the code from a file has already been included, it will not be included again. See the documentation for require() for more information on how this statement works.
require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.
For examples on using require_once() and include_once(), look at the PEAR code included in the latest PHP source code distributions.
Return values are the same as with include(). If the file was already included, this function returns TRUE
Note: require_once() was added in PHP 4.0.1
Note: Be aware, that the behaviour of require_once() and include_once() may not be what you expect on a non case sensitive operating system (such as Windows).
require_once "a.php"; // this will include a.php
require_once "A.php"; // this will include a.php again on Windows! (PHP 4 only)

84. reset (PHP 4, PHP 5)
reset — Set the internal pointer of an array to its first element
mixed reset ( array &$array )
reset() rewinds array's internal pointer to the first element and returns the value of the first array element, or FALSE if the array is empty.
$array = array('step one', 'step two', 'step three', 'step four');

// by default, the pointer is on the first element
echo current($array) . "
n"; // "step one"
// skip two steps
echo current($array) . "
n"; // "step three"

// reset pointer, start again on step one
echo current($array) . "
n"; // "step one"

85. round (PHP 4, PHP 5)
round — Rounds a float
float round ( float $val [, int $precision] )
Returns the rounded value of val to specified precision (number of digits after the decimal point). precision can also be negative or zero (default).
Note: PHP doesn't handle strings like "12,300.2" correctly by default. See converting from strings.
Note: The precision parameter was introduced in PHP 4.
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06

86. rsort (PHP 4, PHP 5)
rsort — Sort an array in reverse order
bool rsort ( array &$array [, int $sort_flags] )
This function sorts an array in reverse order (highest to lowest).
Note: This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
Returns TRUE on success or FALSE on failure.
$fruits = array("lemon", "orange", "banana", "apple");
foreach ($fruits as $key => $val) {
echo "$key = $valn";

The above example will output:
0 = orange
1 = lemon
2 = banana
3 = apple
The fruits have been sorted in reverse alphabetical order.

87. sha1 (PHP 4 >= 4.3.0, PHP 5, PECL hash:1.1-1.3)
sha1 — Calculate the sha1 hash of a string
string sha1 ( string $str [, bool $raw_output] )
Calculates the sha1 hash of str using the US Secure Hash Algorithm 1,
$str = 'apple';

if (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') {
echo "Would you like a green or red apple?";

88. sha1_file (PHP 4 >= 4.3.0, PHP 5, PECL hash:1.1-1.3)
sha1_file — Calculate the sha1 hash of a file
string sha1_file ( string $filename [, bool $raw_output] )
Calculates the sha1 hash of filename using the US Secure Hash Algorithm 1, and returns that hash. The hash is a 40-character hexadecimal number.

89. shuffle (PHP 4, PHP 5)
shuffle — Shuffle an array
bool shuffle ( array &$array )
This function shuffles (randomizes the order of the elements in) an array.
Note: This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
$numbers = range(1, 20);
srand((float)microtime() * 1000000);
foreach ($numbers as $number) {
echo "$number ";

90. sleep (PHP 4, PHP 5)
sleep — Delay execution
int sleep ( int $seconds )
Delays the program execution for the given number of seconds.
// current time
echo date('h:i:s') . "n";
// sleep for 10 seconds
// wake up !
echo date('h:i:s') . "n";

This example will output (after 10 seconds)

91. sort (PHP 4, PHP 5)
sort — Sort an array
bool sort ( array &$array [, int $sort_flags] )
This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.
Note: This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
Returns TRUE on success or FALSE on failure.
$fruits = array("lemon", "orange", "banana", "apple");
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "n";

The above example will output:
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange

92. split (PHP 4, PHP 5)
split — Split string into array by regular expression
array split ( string $pattern, string $string [, int $limit] )
Splits a string into array by regular expression.
// Delimiters may be slash, dot, or hyphen
$date = "04/30/1973";
list($month, $day, $year) = split('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year

93. srand (PHP 4, PHP 5)
srand — Seed the random number generator
void srand ( [int $seed] )
Seeds the random number generator with seed or with a random value if no seed is given.
Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.
// seed with microseconds
function make_seed()
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
$randval = rand();

94. sscanf (PHP 4 >= 4.0.1, PHP 5)
sscanf — Parses input from a string according to a format
mixed sscanf ( string $str, string $format [, mixed &$...] )
The function sscanf() is the input analog of printf(). sscanf() reads from the string str and interprets it according to the specified format, which is described in the documentation for sprintf().
Any whitespace in the format string matches any whitespace in the input string. This means that even a tab t in the format string can match a single space character in the input string.
// getting the serial number
list($serial) = sscanf("SN/2350001", "SN/%d");
// and the date of manufacturing
$mandate = "January 01 2000";
list($month, $day, $year) = sscanf($mandate, "%s %d %d");
echo "Item $serial was manufactured on: $year-" . substr($month, 0, 3) . "-$dayn";

95. stat (PHP 4, PHP 5, PECL maxdb:
stat — Gives information about a file
array stat ( string $filename )
Gathers the statistics of the file named by filename. If filename is a symbolic link, statistics are from the file itself, not the symlink.
lstat() is identical to stat() except it would instead be based off the symlinks status.
Table 94. stat() and fstat() result format
Numeric Associative (since PHP 4.0.6) Description
0 dev device number
1 ino inode number
2 mode inode protection mode
3 nlink number of links
4 uid userid of owner
5 gid groupid of owner
6 rdev device type, if inode device *
7 size size in bytes
8 atime time of last access (Unix timestamp)
9 mtime time of last modification (Unix timestamp)
10 ctime time of last inode change (Unix timestamp)
11 blksize blocksize of filesystem IO *
12 blocks number of blocks allocated *

* Only valid on systems supporting the st_blksize type - other systems (e.g. Windows) return -1.

96. str_ireplace (PHP 5)
str_ireplace — Case-insensitive version of str_replace().
mixed str_ireplace ( mixed $search, mixed $replace, mixed $subject [, int &$count] )
This function returns a string or an array with all occurrences of search in subject (ignoring case) replaced with the given replace value. If you don't need fancy replacing rules, you should generally use this function instead of eregi_replace() or preg_replace() with the i modifier.
$bodytag = str_ireplace("%body%", "black", "");

97. str_pad (PHP 4 >= 4.0.1, PHP 5)
str_pad — Pad a string to a certain length with another string
string str_pad ( string $input, int $pad_length [, string $pad_string [, int $pad_type]] )
This functions returns the input string padded on the left, the right, or both sides to the specified padding length. If the optional argument pad_string is not supplied, the input is padded with spaces, otherwise it is padded with characters from pad_string up to the limit.
$input = "Alien";
echo str_pad($input, 10); // produces "Alien "
echo str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
echo str_pad($input, 6 , "___"); // produces "Alien_"

98. str_repeat (PHP 4, PHP 5)
str_repeat — Repeat a string
string str_repeat ( string $input, int $multiplier )
Returns input repeated multiplier times.
echo str_repeat("-=", 10);

The above example will output:

99. strcmp (PHP 4, PHP 5)
strcmp — Binary safe string comparison
int strcmp ( string $str1, string $str2 )
Note that this comparison is case sensitive.

100. strncasecmp (PHP 4 >= 4.0.2, PHP 5)
strncasecmp — Binary safe case-insensitive string comparison of the first n characters
int strncasecmp ( string $str1, string $str2, int $len )
This function is similar to strcasecmp(), with the difference that you can specify the (upper limit of the) number of characters from each string to be used in the comparison.

101. strcspn (PHP 4, PHP 5)
strcspn — Find length of initial segment not matching mask
int strcspn ( string $str1, string $str2 [, int $start [, int $length]] )
Returns the length of the initial segment of str1 which does not contain any of the characters in str2.

102. strlen (PHP 4, PHP 5)
strlen — Get string length
int strlen ( string $string )
Returns the length of the given string.
$str = 'abcdef';
echo strlen($str); // 6
$str = ' ab cd ';
echo strlen($str); // 7

103. time (PHP 4, PHP 5)
time — Return current Unix timestamp
int time ( void )
Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
$nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs
echo 'Now: '. date('Y-m-d') ."n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."n"; // or using strtotime():
echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."n";

The above example will output something similar to:
Now: 2005-03-30
Next Week: 2005-04-06
Next Week: 2005-04-06

104. uasort (PHP 4, PHP 5)
uasort — Sort an array with a user-defined comparison function and maintain index association
bool uasort ( array &$array, callback $cmp_function )
This function sorts an array such that array indices maintain their correlation with the array elements they are associated with. This is used mainly when sorting associative arrays where the actual element order is significant. The comparison function is user-defined.
Returns TRUE on success or FALSE on failure.

105. uksort (PHP 4, PHP 5)
uksort — Sort an array by keys using a user-defined comparison function
bool uksort ( array &$array, callback $cmp_function )
uksort() will sort the keys of an array using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function.
Function cmp_function should accept two parameters which will be filled by pairs of array keys. The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
Returns TRUE on success or FALSE on failure.
function cmp($a, $b){
$a = ereg_replace('^(a|an|the) ', '', $a);
$b = ereg_replace('^(a|an|the) ', '', $b);
return strcasecmp($a, $b);}
$a = array("John" => 1, "the Earth" => 2, "an apple" => 3, "a banana" => 4);
uksort($a, "cmp");

foreach ($a as $key => $value) {
echo "$key: $valuen";
The above example will output:
an apple: 3
a banana: 4
the Earth: 2
John: 1

106. umask (PHP 4, PHP 5)
umask — Changes the current umask
int umask ( [int $mask] )
umask() sets PHP's umask to mask & 0777 and returns the old umask. When PHP is being used as a server module, the umask is restored when each request is finished.
$old = umask(0);
chmod("/path/some_dir/some_file.txt", 0755);
// Checking
if ($old != umask()) {
die('An error occured while changing back the umask');

107. unlink (PHP 4, PHP 5)
unlink — Deletes a file
bool unlink ( string $filename [, resource $context] )
Deletes filename. Similar to the Unix C unlink() function.

108. unpack (PHP 4, PHP 5)
unpack — Unpack data from binary string
array unpack ( string $format, string $data )
Unpacks from a binary string into an array according to the given format.
unpack() works slightly different from Perl as the unpacked data is stored in an associative array. To accomplish this you have to name the different format codes and separate them by a slash /.
$array = unpack("c2chars/nint", $binarydata);

109. pack (PHP 4, PHP 5)
pack — Pack data into binary string
string pack ( string $format [, mixed $args [, mixed $...]] )
Pack given arguments into binary string according to format.
The idea to this function was taken from Perl and all formatting codes work the same as there, however, there are some formatting codes that are missing such as Perl's "u" format code.
Note that the distinction between signed and unsigned values only affects the function unpack(), where as function pack() gives the same result for signed and unsigned format codes.
Also note that PHP internally stores integer values as signed values of a machine dependent size. If you give it an unsigned integer value too large to be stored that way it is converted to a float which often yields an undesired result.

110. unset (PHP 4, PHP 5)
unset — Unset a given variable
void unset ( mixed $var [, mixed $var [, mixed $...]] )
unset() destroys the specified variables.
The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy.
If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called.
function destroy_foo()
global $foo;
$foo = 'bar';
echo $foo;

The above example will output:

111. usleep (PHP 4, PHP 5)
usleep — Delay execution in microseconds
void usleep ( int $micro_seconds )
Delays program execution for the given number of micro seconds.
echo date('h:i:s') . "n";// Current time
usleep(2000000); // wait for 2 seconds
echo date('h:i:s') . "n"; // back!

The above example will output:

112. var_dump (PHP 4, PHP 5)
var_dump — Dumps information about a variable
void var_dump ( mixed $expression [, mixed $expression [, $...]] )
This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure.
In PHP 5 all public, private and protected properties of objects will be returned in the output.
As with anything that outputs its result directly to the browser, you can use the output-control functions to capture the output of this function, and save it in a string (for example).
$a = array(1, 2, array("a", "b", "c"));
The above example will output:

array(3) {[0]=>int(1) [1]=>int(2) [2]=>array(3) {[0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } }

113. var_export (PHP 4 >= 4.2.0, PHP 5)
var_export — Outputs or returns a parsable string representation of a variable
mixed var_export ( mixed $expression [, bool $return] )
var_export() gets structured information about the given variable. It is similar to var_dump() with one exception: the returned representation is valid PHP code.

114. wordwrap (PHP 4 >= 4.0.2, PHP 5)
wordwrap — Wraps a string to a given number of characters
string wordwrap ( string $str [, int $width [, string $break [, bool $cut]]] )
Wraps a string to a given number of characters using a string break character.
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "
echo $newtext;

115. zend_version (PHP 4, PHP 5)
zend_version — Gets the version of the current Zend engine
string zend_version ( void )
Returns a string containing the version of the currently running Zend Engine.
echo "Zend engine version: " . zend_version();
The above example will output something similar to:
Zend engine version: 2.2.0

116. phpversion (PHP 4, PHP 5)
phpversion — Gets the current PHP version
string phpversion ( [string $extension] )
Returns a string containing the version of the currently running PHP parser or extension.
// prints e.g. 'Current PHP version: 4.1.1'
echo 'Current PHP version: ' . phpversion();
// prints e.g. '2.0' or nothing if the extension isn't enabled
echo phpversion('tidy');

117. phpinfo (PHP 4, PHP 5)
phpinfo — Outputs lots of PHP information
bool phpinfo ( [int $what] )
Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.
Because every system is setup differently, phpinfo() is commonly used to check configuration settings and for available predefined variables on a given system.
phpinfo() is also a valuable debugging tool as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data.

118. array_merge (PHP 4, PHP 5)
array_merge — Merge one or more arrays
array array_merge ( array $array1 [, array $array2 [, array $...]] )
array_merge() merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.
If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended.
If only one array is given and the array is numerically indexed, the keys get reindexed in a continuous way.
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);

The above example will output:
Array([color] => green [0] => 2 [1] => 4 [2] => a [3] => b[shape] => trapezoid [4] => 4)

119. array_values (PHP 4, PHP 5)
array_values — Return all the values of an array
array array_values ( array $input )
array_values() returns all the values from the input array and indexes numerically the array.
$array = array("size" => "XL", "color" => "gold");

The above example will output:
Array( [0] => XL [1] => gold)

120. base64_decode (PHP 4, PHP 5)
base64_decode — Decodes data encoded with MIME base64
string base64_decode ( string $data [, bool $strict] )
Decodes a base64 encoded data.
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);

The above example will output:
This is an encoded string

121. base64_encode (PHP 4, PHP 5)
base64_encode — Encodes data with MIME base64
string base64_encode ( string $data )
Encodes the given data with base64.
This encoding is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.
Base64-encoded data takes about 33% more space than the original data.
$str = 'This is an encoded string';
echo base64_encode($str);

122. basename (PHP 4, PHP 5)
basename — Returns filename component of path
string basename ( string $path [, string $suffix] )
Given a string containing a path to a file, this function will return the base name of the file.

123. chdir (PHP 4, PHP 5)
chdir — Change directory
bool chdir ( string $directory )
Changes PHP's current directory to directory.
// current directory
echo getcwd() . "n";
// current directory
echo getcwd() . "n";

124. checkdate (PHP 4, PHP 5)
checkdate — Validate a Gregorian date
bool checkdate ( int $month, int $day, int $year )
Checks the validity of the date formed by the arguments. A date is considered valid if each parameter is properly defined.
var_dump(checkdate(12, 31, 2000));
var_dump(checkdate(2, 29, 2001));
The above example will output:

125. constant (PHP 4 >= 4.0.4, PHP 5)
constant — Returns the value of a constant
mixed constant ( string $name )
Return the value of the constant indicated by name.
constant() is useful if you need to retrieve the value of a constant, but do not know its name. I.e. it is stored in a variable or returned by a function.
This function works also with class constants.
define("MAXSIZE", 100);
echo constant("MAXSIZE"); // same thing as the previous line

126. Constructors
Constructors are functions in a class that are automatically called when you create a new instance of a class with new. A function becomes a constructor, when it has the same name as the class. If a class has no constructor, the constructor of the base class will be called, if it exists.
class Auto_Cart extends Cart {
function Auto_Cart() {
$this->add_item("10", 1);
This defines a class Auto_Cart that is a Cart plus a constructor which initializes the cart with one item of article number "10" each time a new Auto_Cart is being made with "new". Constructors can take arguments and these arguments can be optional, which makes them much more useful. To be able to still use the class without parameters, all parameters to constructors should be made optional by providing default values.
class Constructor_Cart extends Cart {
function Constructor_Cart($item = "10", $num = 1) {
$this->add_item ($item, $num);
// Shop the same old boring stuff.
$default_cart = new Constructor_Cart;
// Shop for real...
$different_cart = new Constructor_Cart("20", 17);
You also can use the @ operator to mute errors occurring in the constructor, e.g. @new.
class A{
function A() {
echo "I am the constructor of A.
function B() {
echo "I am a regular function named B in class A.
echo "I am not a constructor in A.
class B extends A{ }

// This will call B() as a constructor
$b = new B;

The function B() in class A will suddenly become a constructor in class B, although it was never intended to be. PHP 4 does not care if the function is being defined in class B, or if it has been inherited.
PHP 4 doesn't call constructors of the base class automatically from a constructor of a derived class. It is your responsibility to propagate the call to constructors upstream where appropriate.
Destructors are functions that are called automatically when an object is destroyed, either with unset() or by simply going out of scope. There are no destructors in PHP. You may use register_shutdown_function() instead to simulate most effects of destructors.

127. Destructor
void __destruct ( void )
PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.
class MyDestructableClass {
function __construct() {
print "In constructorn";
$this->name = "MyDestructableClass";
function __destruct() {
print "Destroying " . $this->name . "n";
} }
$obj = new MyDestructableClass();

Like constructors, parent destructors will not be called implicitly by the engine. In order to run a parent destructor, one would have to explicitly call parent::__destruct() in the destructor body.
Note: Destructors called during the script shutdown have HTTP headers already sent. The working directory in the script shutdown phase can be different with some SAPIs (e.g. Apache).
Note: Attempting to throw an exception from a destructor (called in the time of script termination) causes a fatal error.

Today, there have been 105672 visitors (309642 hits) on this page!
=> Do you also want a homepage for free? Then click here! <=