Miscellaneous Function

1.  define :  The define() function defines a constant. Constants are much like variables, except for the following differences:
A constant's value cannot be changed after it is set Constant names do not need a leading dollar sign ($)
Syntax: define(name,value)

<?php
define('i',10);
echo i;          //print 10
echo i++;      //gives an error.
?>
2. constant : The constant() function returns the value of a constant.
Syntax: constant(constant name)

       <?php
define('i',10);
echo constant('i');     //print 10
   ?>
 

3.   include /require: In PHP, you can insert the content of one PHP file into another PHP file before the server executes it. The include and require statements are used to insert useful codes written in other files, in the flow of execution.include will only produce a warning (E_WARNING) and the script will continue require will produce a fatal error (E_COMPILE_ERROR) and stop the script

Syntax: include 'filename';      or  include('filename');
Syntax: require 'filename';      or  require('filename');



Test1.php
<?php
$a=”testing include”;
$b=”testing require”;
?>
Test2.php
<?php
include(‘Test1.php’); echo $a;
?>
//If file Test1.php is available then give output but not available then gives a warning
Test2.php
<?php
require(‘Test1.php’); echo $a;
?>

//If file Test1.php is available then give output but not available then gives an error.
4.   header : The header() function sends a raw HTTP header to a client. Means it will redirect a client to another page. It is important to notice that header() must be called before any actual output is sent.
Syntax: header(string)
<?php
header(“location:test2.php”); //it will redirect to test2.php page
?>
5.   die /exit : The die() or exit() function prints a message and exits the current script
Syntax: die(message)    or exit(message)

<?php
.
.        //this code will execute
.
die(“after this code will no more execute”);
.
.         // this code will not execute.
.
?>
 


No comments:

Post a Comment

=>Advanced Java Programming (J2EE)

1.  Syllabus 2. Unit Wise Question/Material 3. Paper 4. Previous Paper