php - call_user_func_array

Description

mixed call_user_func_array ( callback $function, array $param_arr )
Call a user defined function with the parameters in param_arr.

Parameters


function
The function to be called.
param_arr
The parameters to be passed to the function, as an indexed array.

Return Values

Returns the function result, or FALSE on error.

Examples


Example 742. call_user_func_array() example
<?php

function debug($var, $val)
{
echo
"***DEBUGGING\nVARIABLE: $var\nVALUE:";
if (
is_array($val) || is_object($val) || is_resource($val)) {
print_r($val);
} else {
echo
"\n$val\n";
}
echo
"***\n";
}
$c = mysql_connect();

$host = $_SERVER["SERVER_NAME"];
call_user_func_array('debug', array("host", $host));call_user_func_array('debug', array("c", $c));

call_user_func_array('debug', array("_POST", $_POST));


?>

php - call_user_func

Description

mixed call_user_func ( callback $function [, mixed $parameter [, mixed $...]] )
Call a user defined function given by the function parameter.

Parameters


function
The function to be called. Class methods may also be invoked statically using this function by passing array($classname, $methodname) to this parameter.
parameter
Zero or more parameters to be passed to the function.
Note: Note that the parameters for call_user_func() are not passed by reference. 
<?php 
function increment(&$var) {
$var++;
}
$a = 0;
call_user_func('increment', $a);
echo $a; // 0
call_user_func_array('increment', array(&$a)); // You can use this instead
echo $a; // 1 
?>

Return Values

Returns the function result, or FALSE on error.

Examples


Example 743. call_user_func() example
<?php
function barber($type)
{
echo
"You wanted a $type haircut, no problem";
}

call_user_func('barber', "mushroom");
call_user_func('barber', "shave");
?>

Example 744. Using a class method


<?php

class myclass {

function
say_hello()
{
echo
"Hello!\n";
}
}
$classname = "myclass";
call_user_func(array($classname, 'say_hello'));

?>

php - cal_to_jd

Description

int cal_to_jd ( int $calendar, int $month, int $day, int $year )
cal_to_jd() calculates the Julian day count for a date in the specified calendar. Supported calendars are CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH and CAL_FRENCH.

Parameters



calendar
Calendar to convert from, one of CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH or CAL_FRENCH.
month
The month as a number, the valid range depends on the calendar
day
The day as a number, the valid range depends on the calendar
year
The year as a number, the valid range depends on the calendar

Return Values

A Julian Day number.

php - cal_info

Description

array cal_info ( [int $calendar] )
cal_info() returns information on the specified calendar.
Calendar information is returned as an array containing the elements calname, calsymbol, month, abbrevmonth and maxdaysinmonth. The names of the different calendars which can be used as calendar are as follows:
  • 0 or CAL_GREGORIAN - Gregorian Calendar
  • 1 or CAL_JULIAN - Julian Calendar
  • 2 or CAL_JEWISH - Jewish Calendar
  • 3 or CAL_FRENCH - French Revolutionary Calendar

If no calendar is specified information on all supported calendars is returned as an array.

Parameters



calendar
Calendar to return information for. If no calendar is specified information about all calendars is returned.

Return Values


ChangeLog


Version Description
Since 5.0 The calendar parameter becomes optional and defaults to "all calendars" if omitted.

Examples


Example 358. cal_info() example


<?php

$info
= cal_info(0);

print_r($info);

?>

The above example will output:
Array
(
    [months] => Array
        (
            [1] => January
            [2] => February
            [3] => March
            [4] => April
            [5] => May
            [6] => June
            [7] => July
            [8] => August
            [9] => September
            [10] => October
            [11] => November
            [12] => December
        )

    [abbrevmonths] => Array
        (
            [1] => Jan
            [2] => Feb
            [3] => Mar
            [4] => Apr
            [5] => May
            [6] => Jun
            [7] => Jul
            [8] => Aug
            [9] => Sep
            [10] => Oct
            [11] => Nov
            [12] => Dec
        )

    [maxdaysinmonth] => 31
    [calname] => Gregorian
    [calsymbol] => CAL_GREGORIAN
)

php - cal_from_jd

Description

array cal_from_jd ( int $jd, int $calendar )
cal_from_jd() converts the Julian day given in jd into a date of the specified calendar. Supported calendar values are CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH and CAL_FRENCH.

Parameters



jd
Julian day as integer
calendar
Calendar to convert to

Return Values

Returns an array containing calendar information like month, day, year, day of week, abbreviated and full names of weekday and month and the date in string form "month/day/year".

Examples


Example 357. cal_from_jd() example


<?php

$today
= unixtojd(mktime(0, 0, 0, 8, 16, 2003));

print_r(cal_from_jd($today, CAL_GREGORIAN));

?>

The above example will output:
Array
(
    [date] => 8/16/2003
    [month] => 8
    [day] => 16
    [year] => 2003
    [dow] => 6
    [abbrevdayname] => Sat
    [dayname] => Saturday
    [abbrevmonth] => Aug
    [monthname] => August
)

php - cal_days_in_month

Description

int cal_days_in_month ( int $calendar, int $month, int $year )
This function will return the number of days in the month of year for the specified calendar.

Parameters



calendar
Calendar to use for calculation
month
Month in the selected calendar
year
Year in the selected calendar

Return Values

The length in days of the selected month in the given calendar

Examples


Example 356. cal_days_in_month() example


<?php

$num
= cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31

echo "There was $num days in August 2003";

?>

php - bzwrite

Description

int bzwrite ( resource $bz, string $data [, int $length] )
bzwrite() writes a string into the given bzip2 file stream.

Parameters


bz
The file pointer. It must be valid and must point to a file successfully opened by bzopen().
data
The written data.
length
If supplied, writing will stop after length (uncompressed) bytes have been written or the end of data is reached, whichever comes first.

Return Values

Returns the number of bytes written, or FALSE on error.

Examples


Example 355. bzwrite() example


<?php

$str
= "uncompressed data";

$bz = bzopen("/tmp/foo.bz2", "w");
bzwrite($bz, $str, strlen($str));bzclose($bz);

?>

php - bzread

Description

string bzread ( resource $bz [, int $length] )
bzread() reads from the given bzip2 file pointer.
Reading stops when length (uncompressed) bytes have been read or EOF is reached, whichever comes first.

Parameters



bz
The file pointer. It must be valid and must point to a file successfully opened by bzopen().
length
If not specified, bzread() will read 1024 (uncompressed) bytes at a time.

Return Values

Returns the uncompressed data, or FALSE on error.

Examples


Example 354. bzread() example


<?php

$file
= "/tmp/foo.bz2";$bz = bzopen($file, "r") or die("Couldn't open $file");
$decompressed_file = '';
while (!
feof($bz)) {
$decompressed_file .= bzread($bz, 4096);
}
bzclose($bz);

echo
"The contents of $file are: <br />\n";
echo
$decompressed_file;
?>

php - bzopen

Description

resource bzopen ( string $filename, string $mode )
bzopen() opens a bzip2 (.bz2) file for reading or writing.

Parameters



filename
The name of the file to open.
mode
Similar to the fopen() function ('r' for read, 'w' for write, etc.).

Return Values

If the open fails, bzopen() returns FALSE, otherwise it returns a pointer to the newly opened file.

Examples


Example 353. bzopen() example


<?php

$file
= "/tmp/foo.bz2";$bz = bzopen($file, "r") or die("Couldn't open $file for reading");
bzclose($bz);
?>

php - bzerror

Description

array bzerror ( resource $bz )
Returns the error number and error string of any bzip2 error returned by the given file pointer.

Parameters



bz
The file pointer. It must be valid and must point to a file successfully opened by bzopen().

Return Values

Returns an associative array, with the error code in the errno entry, and the error message in the errstr entry.

Examples


Example 352. bzerror() example


<?php

$error
= bzerror($bz);

echo
$error["errno"];
echo
$error["errstr"];

?>