0% found this document useful (0 votes)
319 views

PHP Miscellaneous Function

This document discusses several PHP functions: - define() defines constants that cannot be changed and do not require a leading $ like variables. - constant() returns the value of a defined constant. - include() and require() include other PHP files, with require() producing a fatal error if the file is not found. - header() sends HTTP headers, which must be called before any output. - die() prints a message and exits the current script, serving as an alias for exit().

Uploaded by

vadgamabhavin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
319 views

PHP Miscellaneous Function

This document discusses several PHP functions: - define() defines constants that cannot be changed and do not require a leading $ like variables. - constant() returns the value of a defined constant. - include() and require() include other PHP files, with require() producing a fatal error if the file is not found. - header() sends HTTP headers, which must be called before any output. - die() prints a message and exits the current script, serving as an alias for exit().

Uploaded by

vadgamabhavin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Miscellaneous Function

Haresh Khachariya
(Lecturer)
Shree M & N Virani Science College ,
Rajkot

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
($)
Constant values can only be strings and numbers
2

Syntax & Example

define(name,value,case_insensitive)

<?php
define("GREETING","Hello you! How are you
today?");
echo constant("GREETING");
?>

<?php
define("GREETING","Hello you! How are you
today?",TRUE);
echo constant("greeting");
?>

constant()
The constant() function returns the value

of a

constant.
constant(constant)

<?php
define("GREETING","Hello you! How are you

today?");
echo constant("GREETING");
?>

include()

The include() statement is used to include a php file


in another file. This way can include multiple files
through include() statement in php file.

If a.php is a php script calling b.php with include()


statement, and does not find b.php, a.php executes
with a warning, excluding the part of the code
written within b.php.
6

Syntax & Example


include will

only produce a warning


(E_WARNING) and the script will continue

include 'filename';

<?php

include('myinclude.php');
echo This is include function;
?>
7

require

The require() statement is used to include a php


file in another file.

This way can


include multiple
through require() statement in php file.

require
will
produce
a
fatal
error
(E_COMPILE_ERROR) and stop the script

files

Syntax and Example


reuire

(file_name);

<?php

require('myinclude.php');

echo This is include function;


?>

header()

The header() function sends a raw HTTP header to a


client.

It is important to notice that header() must be called


before any actual output is sent.

10

Syntax
header(string,replace,http_response_code)

Parameter

Description

string

Required. Specifies the header


string to send

replace

Optional. Indicates whether the


header should replace previous or
add a second header. Default is
TRUE (will replace). FALSE (allows
multiple headers of the same type)

http_response_code

Optional. Forces the HTTP response


code to the specified value

11

Example

header("Location: http://google.com");

header("Location: pages/page.php");

header("Location: http://google.com", true, 303);

header("Location: http://google.com", true);

12

die()
The die() function prints

a message and exits

the current script.


This function is an alias

of the exit() function.

13

Syntax and Example


die(message)

<?php

die("This is die function.");


?>

14

Questions?

You might also like