Tuesday 29 November 2011

Miscellaneous Function


Ø       define()

  • Defines a named constant at runtime.
  • Returns true on success or false on failure.

Syntax

                   bool define(string $name, mixed $value [,bool $case_insensitive=false])

Parameter
Description
$name
The name of the constant
$vallue
The value of the constant. Only scalar and null values are allowed.
$case_insensitive
If set to true, the constant will be defined case-insensitive. The default behavior is case- sensitive.


Example

<?php
          define("STR","Hello World");
          echo STR;
?>

Output  

                   Hello World

Ø       constant()

  • 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.

Syntax

                   mixed constant(string $name)

Example

<?php
          define("STR","Hello World");
          echo constant("STR");
?>

Output  

                   Hello World

Ø       include()

  • This function is used to include the file into the other file so that the content from one file can be accessed into the other file.

Syntax

                   include(string filename)

Example  - first.php

<?php
          include("second.php");
          main();
?>

Example  - second.php

<?php
          function main()
          {
                   echo "main() function is called.";
          }
?>

Output  

                   Hello World

Ø       require()

  • This function is similar to that of the include function expect that the require function will generate fatal error if the file is not found and will not execute the remaining code of php.

Syntax

                   require(string filename)

Example 

<?php
          require("second.php");
          main();
?>

Ø       header()

  • This function is used when there is a requirement to transfer the page from one web page to another directly without using link.

Syntax

                   header(“Location: filename”)

Example 

<?php
          $user="Hemangi";
          $pass="123";
          if($user="Hemangi" and $pass="123")
          {
                   header("Location: test.php");
          }
?>

Ø       die()

  • This function is similar to exit. When the user want the web page should be closed, for that die function is used.

Syntax

                   Void die()

Example 

 <?php
          echo "Hello World";    //Hello World
          die();
          echo "hiii...";
 ?>

Posted By : Hemangi Zala

No comments:

Post a Comment