Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Php Lecture Notes
1. PHPWhat can PHP do?
What is a PHP File?
Why PHP?
Mrs .C.Santhiya
Assistant Professor
TCE,Madurai
2. Background
PHP is server side scripting system.
PHP stands for "PHP: Hypertext Preprocessor“
Syntax based on Perl, Java, and C
Very good for creating dynamic content
Powerful, but somewhat risky!
If you want to focus on one system for dynamic content,
this is a good one to choose
3. PHP Scripts
Typically file ends in .php--this is set by the web server
configuration
Separated in files with the <?php ?> tag
php commands can make up an entire file, or can be
contained in html--this is a choice….
Program lines end in ";" or you get an error
Server recognizes embedded script and executes
Result is passed to browser, source isn't visible
<?php $myvar = "Hello World!";
echo $myvar;?>
4. Two Ways
You can embed sections of php inside html:
<BODY>
<P>
<?php $myvar = "Hello World!";
echo $myvar;</P>
</BODY>
Or you can call html from php:
<?php
echo "<html><head><title>Howdy</title>
…
?>
5. Code:
<?php
echo "Hello world!";
?>
Run a php file
http://www.wampserver.com
Go to start & start wamp server
Open browser & http://local host
Put php file in www folder c://wamp/www
http:///local host/filename.php
7. Literals
All strings must be enclosed in single of
doublequotes: ‘Hello’ or “Hello”.
Numbers are not in enclosed in quotes: 1 or 45
or34.564
Booleans (true/false) can be written directly as
true or false.
8. Comments
// This is a comment
# This is also a comment
/* This is a comment
that is spread over
multiple lines */
9. Displaying Data
There are two language constructs available todisplay data: print() and
echo().
They can be used with or without brackets.
Note that the data ‘displayed’ by PHP is actually parsed by your
browser as HTML. View source to see actual output.
<?php
echo ‘Hello World!<br />’;
echo(‘Hello World!<br />’);
print ‘Hello World!<br />’;
print(‘Hello World!<br />’);
?>
11. Variables: What are they?
labelled ‘places’ are called VARIABLES
$ followed by variable name
Case sensitive
$variable differs from $Variable
Stick to lower-case to be sure!
Name must started with a letter or an underscore
Followed by any number of letters, numbers and underscores
<?php
$name = ‘Phil’;
$age = 23;
echo $name;
echo ’ is ‘;
echo $age;
// Phil is 23
?>
12. Variables: What are they?
Assigned by value
$foo = "Bob"; $bar = $foo;
Assigned by reference, this links vars
$bar = &$foo
Some are preassigned, server and env vars
For example, there are PHP vars, eg. PHP_SELF,
HTTP_GET_VARS,etc
13. Constants
Constants (unchangeable variables) can also be
defined.
Each constant is given a name (note no
preceding dollar is applied here).
By convention, constant names are usually in
UPPERCASE
<?php
define(‘NAME’,‘Phil’);
define(‘AGE’,23);
echo NAME;
echo ’ is ‘;
echo AGE;
// Phil is 23
?>
14. Operators
Arithmetic (+, -, *, /, %) and String (.)Arithmetic (+, -, *, /, %) and String (.)
Assignment (=) and combined assignmentAssignment (=) and combined assignment
$a = 3;
$a += 5; // sets $a to 8;
$b = "Hello ";
$b .= "There!"; // sets $b to "Hello There!";
Bitwise (&, |, ^, ~, <<, >>)Bitwise (&, |, ^, ~, <<, >>)
$a ^ $b
~ $a
Comparison (==, ===, !=, !==, <, >, <=, >=)Comparison (==, ===, !=, !==, <, >, <=, >=)
Error Control (@)Error Control (@)
Execution (` is similar to the shell_exec() function)Execution (` is similar to the shell_exec() function)
Incrementing/DecrementingIncrementing/Decrementing
15. Logical
$a and $b And True if both $a and $b
are true.
$a or $b Or True if either $a or $b
is true.
$a xor $b Xor True if either $a or $b
is true,
but not both.
! $a Not True if $a is not true.
$a && $b And True if both $a and $b
are true.
++$a (Increments by one, then returns++$a (Increments by one, then returns
$a.)$a.)
$a++ (Returns $a, then increments $a$a++ (Returns $a, then increments $a
by one.)by one.)
--$a--$a (Decrements $a by one, then(Decrements $a by one, then
returns $a.)returns $a.)
$a--$a-- (Returns $a, then decrements $a(Returns $a, then decrements $a
by one.)by one.)
16. Control Structures
Wide Variety available
if, else, elseif
while, do-while
for, foreach
break, continue, switch
require, include, require_once, include_once