--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD - IT)
Contact No : 7600044051
E-Mail : rupareleducation@gmail.com
PHP Miscellaneous Function
No
|
Name
|
Description
|
1
|
Define()
|
It is used to
define a named constant at runtime.
Syntax:
define(string $name,$value[,bool
$case_insensetive=false]);
If it sets to
true, the constant will be defined case insensitive. The default behavior is
case sensitive.
It returns TRUE
on success or FALSE on failure.
Example:
<?php
define(“CONSTANT”,”Hello World.”);
echo CONSTANT; //output’s
“Hello World”
echo Constant;
//output’s “Constant” and issue a notice.
define(“GREETING”,”Hello you.”,true);
echo Greeting; //output’s
“Hello you”.
?>
|
2
|
Constant()
|
It returns 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.
·
It
is stored in a variable or returned by a function.
·
This
function works also with class constant.
·
Syntax:
constant(string $name);
·
It
returns the value of the constant or NULL if
the constant is not defined.
Example
<?php
define(“MAXSIZE”,100);
echo constant(“MAXSIZE”);
?>
|
3
|
include()
|
The include()
statement includes and evaluates the specified file.
ð
The
code it contains inherits the variable scope of the line on which the include
occurs
ð
Any
variable available at that line in the calling file will be available within
the called file, from that point forward.
ð
Syntax:
include(string ‘file-name’);
ð
The
include function requires two file to execute.
Example
File1.php
<?php
$color=’green’;
$fruit=’apple’;
?>
File2.php
<?php
include(“file1.php”);
echo “A $color $fruit”;
?>
|
4
|
require()
|
Require() is
identical to include() except upon failure it will produce a fatal error.
In other words ,
it will halt the script whereas include() only emits a warning which allows
the script to continue.
|
5
|
header()
|
header is used
to send a raw http header.
remember that
header() must be called before any actual output is sent, either by normal
HTML tags, blank lines in a file.
It is a very
common error to read code with include(), or require(), functions or another
file access function and have spaces or empty lines that are output before
header is called.
Syntax:
header(string
$string[,int $http_response_code]);
Example
<?php
header(‘URL’);
?>
|
6
|
die() or exit ()
|
The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script.
The exit() function only terminates the execution of the script. The shutdown functions and object destructors will always be executed even if exit() function is called. The exit() function is an alias of the die() function.
Syntax
die(parameter) or exit (Parameter)
|
:: Best Of Luck ::
Please Share and Comment it.... Thank You.