INTRODUCTION
TO PHP
1monica Deshmane(H.V.Desai College,Pune)
Introduction to PHP
The recursive acronym for PHP is Hypertext Preprocessor.
open source general purpose language, invented by Rasmus Lerdorf in
1994.
PHP is server-side, cross platform, HTML embedded scripting
language.
PHP code is executed on server, then server generates HTML response
that will be given back to the client.
PHP Script runs only when some event occurred.
ForStaticHTMLpages
3)What does PHP do?
3)What does PHP do?
For server side scripting technologies
Features of php
1. Php supports most of web browsers & Servers.
2. PHP supports variety of simple editors.
3. PHP supports wide range of protocols.
4. Supports range of databases.
5. Supports various operating systems.
6. Open source & easy to code.
monica Deshmane(H.V.Desai College,Pune)
Difference between HTML & PHP
HTML PHP
Client side Server Side
<html></html> <?php ?>
Static web page
generation
Dynamic web page
generation
No sessions,cookies to
maintain state
sessions, cookies present to
maintain state
monica Deshmane(H.V.Desai College,Pune)
PHP - Lexical Structure
•The lexical structure of a programming language is the
set of basic rules that governs how you write programs in
that language.
•PHP Syntax:
<?php
//PHP code
?>
•Embeding: PHP code is inserted into an HTML page
between the start and end tags <? and ?>. The word PHP
follows the start tag.
//html code
<?php ... PHP code ?>
//html code.
1. The names of user-defined classes and functions, as
well as built-in constructs and keywords are case-
insensitive.
echo("hello, world");
ECHO("hello, world");
EcHo("hello, world");
2. Variables are case sensitive.
$name, $NAME, and $NaME
These are 3 different variables.
PHP - Lexical Structure
Case Sensitivity
monica Deshmane(H.V.Desai College,Pune)
PHP uses semicolons to separate simple statements.
A compound statement that uses curly braces to
mark a block of code does not need a semicolon after
the closing brace.
The semicolon before the closing brace is not
optional.
The semicolon before a closing PHP tag is optional.
Statements and Semicolons
monica Deshmane(H.V.Desai College,Pune)
•Whitespace and linebreaks:
White space and line breaks are ignored in a
PHP program. A statement can be spread
across any number of lines.
•Literals
A literal is constant value that appears directly in a
program.
•The following are all literals in PHP:
2001 0xF 1.41454 "HelloWorld" 'Hi gm' true null
monica Deshmane(H.V.Desai College,Pune)
Comments
Comments are ignored.
There are three styles of comments in PHP:
1. Shell-style comments:
When PHP encounters a hash mark (#) within the code,
everything from the hash mark to the end of the line or the
end of the section of PHP code (whichever comes first) is
considered a comment.
e.g.<?php $d = 4 #Set $d to 4
?>
<?php echo $d ?>
2. C++ style comments: When PHP encounters two slash
characters (//) within the code, everything from the slashes
to the end of the line or the end of the section of PHP code.
monica Deshmane(H.V.Desai College,Pune)
•Comments: continue…
e.g.
<?php $d = 4 //Set $d to 4
?>
<?php echo $d ?>
3. C style comments: When PHP encounters
a slash followed by an asterisk, (/*)
everything after that until it encounters an
asterisk followed by a slash (*/) is considered
a comment.
This style of comment, unlike the other two,
can span multiple lines. Also, C style
comments continue past end markers.
<?php $d = 4 /* Set $d to 4 */ ?>
<?php echo $d ?>
Identifiers:
Identifers are used to name variables, functions,
constants, and classes. The first character of an
identifier must be either an ASCII letter, the
underscore character (_). After the initial character,
these characters and the digits 0-9 are valid.
Variable names:
Variable names always begin with a dollar sign ($)
and are case sensitive.
Valid variable names:
$bill, $head_count, $MaximumForce,
$_underscore, $_int
Invalid variable names:
$not valid, $|, $3wa
monica Deshmane(H.V.Desai College,Pune)
Function names:
Function names are not case sensitive.
Here are some valid function names:
Tally, list_all_users, deleteTclFiles,
LOWERCASE_IS_FOR_WIMPS, _hide
Following refers one function:
echo("hello, world");
ECHO("hello, world");
EcHo("hello, world");
Class names:
Class names follow the standard rules for PHP identifiers
and are not case sensitive. The class name stdClass is
reserved.
Valid class names:
Employee, Account
Constants:
A constant is an identifier for a simple value; only
boolean, integer, double, and string-can be constants.
Once set, the value of a constant cannot change.
Constants are referred to by their identifiers and are set
using the define( ) function:
define('PUBLISHER', "O'Reilly & Associates");
echo PUBLISHER;
Keywords:
A keyword is a word reserved by the language for
its core functionality.
You cannot give a variable, function, class, or
constant the same name as a keyword.
In addition, you cannot use an identifier that is the
same as a built-in PHP function.
monica Deshmane(H.V.Desai College,Pune)
Q.1Whole PHP code is case sensitive?
Q2.Explaincomments in PHP
Q.3. What PHP does?
Q.4. What are features of PHP?
17monica Deshmane

Chap1introppt1php basic

  • 1.
  • 2.
    Introduction to PHP Therecursive acronym for PHP is Hypertext Preprocessor. open source general purpose language, invented by Rasmus Lerdorf in 1994. PHP is server-side, cross platform, HTML embedded scripting language. PHP code is executed on server, then server generates HTML response that will be given back to the client. PHP Script runs only when some event occurred.
  • 3.
  • 4.
    3)What does PHPdo? For server side scripting technologies
  • 5.
    Features of php 1.Php supports most of web browsers & Servers. 2. PHP supports variety of simple editors. 3. PHP supports wide range of protocols. 4. Supports range of databases. 5. Supports various operating systems. 6. Open source & easy to code. monica Deshmane(H.V.Desai College,Pune)
  • 6.
    Difference between HTML& PHP HTML PHP Client side Server Side <html></html> <?php ?> Static web page generation Dynamic web page generation No sessions,cookies to maintain state sessions, cookies present to maintain state monica Deshmane(H.V.Desai College,Pune)
  • 7.
    PHP - LexicalStructure •The lexical structure of a programming language is the set of basic rules that governs how you write programs in that language. •PHP Syntax: <?php //PHP code ?> •Embeding: PHP code is inserted into an HTML page between the start and end tags <? and ?>. The word PHP follows the start tag. //html code <?php ... PHP code ?> //html code.
  • 8.
    1. The namesof user-defined classes and functions, as well as built-in constructs and keywords are case- insensitive. echo("hello, world"); ECHO("hello, world"); EcHo("hello, world"); 2. Variables are case sensitive. $name, $NAME, and $NaME These are 3 different variables. PHP - Lexical Structure Case Sensitivity monica Deshmane(H.V.Desai College,Pune)
  • 9.
    PHP uses semicolonsto separate simple statements. A compound statement that uses curly braces to mark a block of code does not need a semicolon after the closing brace. The semicolon before the closing brace is not optional. The semicolon before a closing PHP tag is optional. Statements and Semicolons monica Deshmane(H.V.Desai College,Pune)
  • 10.
    •Whitespace and linebreaks: Whitespace and line breaks are ignored in a PHP program. A statement can be spread across any number of lines. •Literals A literal is constant value that appears directly in a program. •The following are all literals in PHP: 2001 0xF 1.41454 "HelloWorld" 'Hi gm' true null monica Deshmane(H.V.Desai College,Pune)
  • 11.
    Comments Comments are ignored. Thereare three styles of comments in PHP: 1. Shell-style comments: When PHP encounters a hash mark (#) within the code, everything from the hash mark to the end of the line or the end of the section of PHP code (whichever comes first) is considered a comment. e.g.<?php $d = 4 #Set $d to 4 ?> <?php echo $d ?> 2. C++ style comments: When PHP encounters two slash characters (//) within the code, everything from the slashes to the end of the line or the end of the section of PHP code. monica Deshmane(H.V.Desai College,Pune)
  • 12.
    •Comments: continue… e.g. <?php $d= 4 //Set $d to 4 ?> <?php echo $d ?> 3. C style comments: When PHP encounters a slash followed by an asterisk, (/*) everything after that until it encounters an asterisk followed by a slash (*/) is considered a comment. This style of comment, unlike the other two, can span multiple lines. Also, C style comments continue past end markers. <?php $d = 4 /* Set $d to 4 */ ?> <?php echo $d ?>
  • 13.
    Identifiers: Identifers are usedto name variables, functions, constants, and classes. The first character of an identifier must be either an ASCII letter, the underscore character (_). After the initial character, these characters and the digits 0-9 are valid. Variable names: Variable names always begin with a dollar sign ($) and are case sensitive. Valid variable names: $bill, $head_count, $MaximumForce, $_underscore, $_int Invalid variable names: $not valid, $|, $3wa monica Deshmane(H.V.Desai College,Pune)
  • 14.
    Function names: Function namesare not case sensitive. Here are some valid function names: Tally, list_all_users, deleteTclFiles, LOWERCASE_IS_FOR_WIMPS, _hide Following refers one function: echo("hello, world"); ECHO("hello, world"); EcHo("hello, world");
  • 15.
    Class names: Class namesfollow the standard rules for PHP identifiers and are not case sensitive. The class name stdClass is reserved. Valid class names: Employee, Account Constants: A constant is an identifier for a simple value; only boolean, integer, double, and string-can be constants. Once set, the value of a constant cannot change. Constants are referred to by their identifiers and are set using the define( ) function: define('PUBLISHER', "O'Reilly & Associates"); echo PUBLISHER;
  • 16.
    Keywords: A keyword isa word reserved by the language for its core functionality. You cannot give a variable, function, class, or constant the same name as a keyword. In addition, you cannot use an identifier that is the same as a built-in PHP function. monica Deshmane(H.V.Desai College,Pune)
  • 17.
    Q.1Whole PHP codeis case sensitive? Q2.Explaincomments in PHP Q.3. What PHP does? Q.4. What are features of PHP? 17monica Deshmane