Académique Documents
Professionnel Documents
Culture Documents
PHP Basics
rather, it passes only those pages identified by a specific file extension (.php)
Engine needs some means to immediately
code.
PHP Basics 1.3 Ajay Rawat : arawat@ddn.upes.ac.in
Syntax
Style
PHP Basics
1.4
Default Syntax
The default delimiter syntax opens with <?php and
PHP Basics
1.5
Short-Tags
<? print "This is another PHP example."; ?>
short_open_tag directive.
Although short-tag delimiters are convenient,
keep in mind that they clash with XML, and thus XHTML, syntax.
Therefore, for conformance reasons we
as short-circuit syntax.
PHP Basics 1.6 Ajay Rawat : arawat@ddn.upes.ac.in
Script
Certain Editor like Microsofts FrontPage editor
PHP Basics
1.7
ASP Style
<% print "This is another PHP example."; %>
ASP-style syntax was removed as of PHP 5.3. Keep in mind that just we can do something
PHP Basics
1.8
PHP Basics
1.9
Comments
PHP Basics
Comments
Comments are user for our own benefit or for
PHP Basics
1.11
conclusion.
PHP Basics
1.12
Shell Syntax
PHP also supports an alternative to the C++-
PHP Basics
1.13
Multiple-Line C Syntax
It support more verbose functional description
PHP Basics
1.14
HTML Comment
Keep in mind that if we want to place a
comment in HTML we need to use the open comment <!-- and close comment --> tags.
PHP Basics
1.15
PHP Basics
print() statement
The print() statement outputs data passed to it
to the browser.
int print(argument).
PHP Basics
1.17
print() statement
print() is not actually a real function (it is a
language construct) so we are not required to use parentheses with its argument list.
The print() statement return value is
PHP Basics
1.18
echo() statement
void echo ( string $arg1 [, string $... ] )
Outputs all parameters. echo() is not a function (it is a language
construct.
If we want to pass more than one parameter to
PHP Basics
1.19
echo() statement
PHP Basics
1.20
printf() statement
printf() statement is used to when to blend of
PHP Basics
1.21
sprintf() statement
The sprintf() statement is functionally identical
to printf() except that the output is assigned to a string rather than rendered to the browser.
string sprintf(string format [, mixed arguments])
An example follows: $cost = sprintf("$%.2f", 43.2); // $cost = $43.20
PHP Basics
1.22
PHP Basics
Data types
A data type is the generic name assigned to
PHP Basics
1.24
Boolean
The Boolean datatype is named after George
Boole (18151864).
A Boolean variable represents truth,
PHP Basics
1.25
Integer
An integer is representative of any whole
platform-dependent.
PHP 5(earlier) introduced a 32-bit integer
value.
PHP 6 introduced a 64-bit integer value,
PHP Basics 1.26 Ajay Rawat : arawat@ddn.upes.ac.in
Float
Floating-point numbers, also referred as floats,
fractional parts.
Floats are used to represent monetary values,
weights, distances.
4.5678
4.0 8.7e4 1.23E+11
PHP Basics 1.27 Ajay Rawat : arawat@ddn.upes.ac.in
String
A string is a sequence of characters treated as
a contiguous group.
Strings are delimited by single or double
quotes.
"PHP is a great language "123$%^789.
PHP Basics
1.28
Array
It is a aggregate a series of similar items
of data values.
Each member of the array index (also known
Object
The object is a central concept of the object-
PHP Basics
1.30
Type Cast
Converting values from one datatype to
PHP Basics
1.31
Type-Related Functions
Retrieving Types
The
In
total, eight possible return values are available: array, boolean, double, integer, object, resource, string, and unknown type. gettype (mixed var)
string
PHP Basics
1.32
Type-Related Functions
Converting Types
The
settype() function converts a variable, specified by var, to the type specified by type. possible type values are available: array, boolean, float, integer, null, object, and string. the conversion is successful, TRUE is returned; otherwise, FALSE is returned.
Seven
If
boolean
PHP Basics
determining a variables type, including is_array(), is_bool(), is_float(), is_integer(), is_null(), is_numeric(), is_object(), is_resource(), is_scalar(), and is_string().
boolean is_name(mixed var)
PHP Basics
1.34
Identifier
Identifier is a term applied to variables,
underscore characters
PHP Basics
1.35
Variables
A variable is a symbol that can store different
contains data and may be manipulated throughout the execution of the program.
Variable Declaration:
A variable
always begins with a dollar sign, $, which is then followed by the variable name.
$color,
PHP Basics
1.36
Variables
Note that variables are case sensitive. $color, $Color, $COLOR
Value Assignment:
$color
= "red";
PHP Basics
1.37
Variables
Reference Assignment:
We We
can create a variable that refers to the same content as another variable does. can assign variables by reference by appending an ampersand (&) to the equal sign. =& $value1; // $value1 and $value2 both equal "Hello
$value2
PHP Basics
1.38
Variables Scope
We can declare variable anywhere in a PHP
script.
The location of the declaration influences the
scope.
PHP variables can be one of four scope types:
Local
variables
Local Variable
A variable declared in a function is considered
local.
Means it can be referenced only in that
function.
Any assignment outside of that function will be
PHP Basics
1.40
Local Variable
They eliminate the possibility of unexpected
side effects, which can result from globally accessible variables that are modified, intentionally or not.
PHP Basics
1.41
Function Variable
Function parameters are declared after the
PHP Basics
1.42
Global Variable
A global variable can be accessed in any part
of the program.
To modify it must be explicitly declared to be
existing variable tells PHP to use the variable having that name.
PHP Basics 1.43 Ajay Rawat : arawat@ddn.upes.ac.in
Global Variable
PHP Basics
1.44
Static Variables
A static variable does not lose its value when
again.
Static scoping is particularly useful for
recursive functions.
PHP Basics
1.45
that are accessible from anywhere and provide environment specific information.
With these variable we can get details about:
current
users local
user session
operating environment
operating environment
availability and value of other variables are specific to the O.S and Web server.
PHP Basics 1.46 Ajay Rawat : arawat@ddn.upes.ac.in
PHP Basics
1.47
Variable Variables
To use a variable whose content can be
placing a second dollar sign in front of the original variable name and again assigning another value:
$$recipe = "& meatballs";
This in effect assigns & meatballs to a variable
named pasta.
PHP Basics 1.48 Ajay Rawat : arawat@ddn.upes.ac.in
Variable Variables
The two snippets of code produce the same
result:
echo $recipe $pasta; echo $recipe ${$recipe};
meatballs.
PHP Basics
1.49
Constants
A constant is a value that cannot be modified
function.
define("PI", 3.141592);
PHP Basics
1.50
dollar sign.
We cant redefine or undefine the constant
PHP Basics
1.51
End of Chapter
PHP Basics