0% found this document useful (0 votes)
42 views29 pages

PHP Part1

The document outlines an introductory course on HTML, CSS, JavaScript, PHP and MySQL. It covers topics like HTML lists, tables and links, CSS, JavaScript events, what PHP is and how it is used with MySQL for dynamic web development. It also provides basic explanations of PHP syntax, variables, data types, scope and how to install PHP and other software needed to set up a development environment.

Uploaded by

Rubab Safdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views29 pages

PHP Part1

The document outlines an introductory course on HTML, CSS, JavaScript, PHP and MySQL. It covers topics like HTML lists, tables and links, CSS, JavaScript events, what PHP is and how it is used with MySQL for dynamic web development. It also provides basic explanations of PHP syntax, variables, data types, scope and how to install PHP and other software needed to set up a development environment.

Uploaded by

Rubab Safdar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Course Outline

 HTML (Intro)
 HTML (Lists)
 HTML (Tables, Links)
 HTML (Images and Image Map, Frames)
 HTML (Cascading Style Sheets)
 JavaScript (Basic Operation)
 JavaScript (System Event)

Mr. Bilal Sadique (USA)


2

PHP: Hypertext Preprocessor


Part 1

Mr. Bilal Sadique (USA)


PHP
3

 PHP is a server-side scripting language.


What You Should Already Know
 Before you continue you should have a basic
understanding of the following:
 HTML/XHTML
 JavaScript

Mr. Bilal Sadique (USA)


What is PHP?
4

 PHP stands for PHP: Hypertext Preprocessor


 PHP is a server-side scripting language, like ASP
 PHP scripts are executed on the server
 PHP supports many databases (MySQL, Informix,
Oracle, Sybase, Solid, PostgreSQL, Generic ODBC,
etc.)
 PHP is an open source software
 PHP is free to download and use

Mr. Bilal Sadique (USA)


What is a PHP File?
5

 PHP files can contain text, HTML tags and scripts


 PHP files are returned to the browser as plain
HTML
 PHP files have a file extension of ".php", ".php3", or
".phtml"

Mr. Bilal Sadique (USA)


What is MySQL?
6

 MySQL is a database server


 MySQL is ideal for both small and large applications
 MySQL supports standard SQL
 MySQL compiles on a number of platforms
 MySQL is free to download and use

Mr. Bilal Sadique (USA)


PHP + MySQL
7

 PHP combined with MySQL are cross-platform (you


can develop in Windows and serve on a Unix
platform)

Mr. Bilal Sadique (USA)


Why PHP?
8

 PHP runs on different platforms (Windows, Linux,


Unix, etc.)
 PHP is compatible with almost all servers used today
(Apache, IIS, etc.)
 PHP is FREE to download from the official PHP
resource: www.php.net
 PHP is easy to learn and runs efficiently on the
server side

Mr. Bilal Sadique (USA)


Where to Start?
9

 To get access to a web server with PHP support, you


can:
 Install Apache (or IIS) on your own server, install
PHP, and MySQL
 Or find a web hosting plan with PHP and MySQL
support

Mr. Bilal Sadique (USA)


What do you Need?
10

 If your server supports PHP you don't need to do


anything.
 Just create some .php files in your web directory, and
the server will parse them for you. Because it is free,
most web hosts offer PHP support.
 However, if your server does not support PHP, you
must install PHP.
 Here is a link to a good tutorial from PHP.net on
how to install
PHP5:http://www.php.net/manual/en/install.php

Mr. Bilal Sadique (USA)


Download PHP
11

 Download PHP for free


here: http://www.php.net/downloads.php
 Download MySQL for free
here: http://www.mysql.com/downloads/
 Download Apache for free
here: http://httpd.apache.org/download.cgi
OR
Download WAMP Server
http://www.wampserver.com/en/download.php

Mr. Bilal Sadique (USA)


Basic PHP Syntax
12

 A PHP scripting block always starts with <?php and


ends with ?>. A PHP scripting block can be placed
anywhere in the document.
 On servers with shorthand support enabled you can
start a scripting block with <? and end with ?>.
 For maximum compatibility, we recommend that
you use the standard form (<?php) rather than the
shorthand form.

Mr. Bilal Sadique (USA)


Basic PHP Syntax
13

 A PHP file normally contains HTML tags, just like an


HTML file, and some PHP scripting code.
 Below, we have an example of a simple PHP script
which sends the text "Hello World" to the browser:

Mr. Bilal Sadique (USA)


Basic PHP Syntax
14

<html>
<body>

<?php
echo "Hello World";
?>

</body>
</html>

Mr. Bilal Sadique (USA)


Basic PHP Syntax
15

Each code line in PHP must end with a semicolon.


The semicolon is a separator and is used to
distinguish one set of instructions from another.
There are two basic statements to output text with
PHP: echo and print. In the example above we have
used the echo statement to output the text "Hello
World".

Mr. Bilal Sadique (USA)


Comments in PHP
16

In PHP, we use // to make a single-line comment or /* and */ to make


a large comment block.
<html>
<body>

<?php
//This is a comment
/*
This is
a comment
block
*/
?>

</body>
</html>

Mr. Bilal Sadique (USA)


PHP Case Sensitivity
17

 In PHP, all user-defined functions, classes, and


keywords (e.g. if, else, while, echo, etc.) are case-
insensitive.
 In the example below, all three echo statements
below are legal (and equal):

Mr. Bilal Sadique (USA)


PHP Case Sensitivity
18

 In PHP, all variables are case-sensitive.


 In the example below, only the first statement will
display the value of the $color variable (this is
because $color, $COLOR, and $coLOR are treated as
three different variables):

Mr. Bilal Sadique (USA)


PHP Variables
19

 Variables are "containers" for storing information:

<html><body>
<?php
$x=5;
$y=6;
$z=$x+$y;
echo “$z”;
?>
</body></html>

Result is: 11

Mr. Bilal Sadique (USA)


PHP Variables
20

 As with algebra, PHP variables can be used to hold values


(x=5) or expressions (z=x+y).
 A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume).
 Rules for PHP variables:
 A variable starts with the $ sign, followed by the name of the
variable
 A variable name must start with a letter or the underscore
character
 A variable name cannot start with a number
 A variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ )
 Variable names are case sensitive ($y and $Y are two different
variables)

Mr. Bilal Sadique (USA)


Creating (Declaring) PHP Variables
21

 PHP has no command for declaring a variable.


 A variable is created the moment you first assign a
value to it:

Mr. Bilal Sadique (USA)


PHP is a Loosely Type Language
22

 In the example above, notice that we did not have to


tell PHP which data type the variable is.
 PHP automatically converts the variable to the
correct data type, depending on its value.
 In other languages such as C, C++, the programmer
must declare the name and type of the variable
before using it.

Mr. Bilal Sadique (USA)


PHP Variables Scope
23

 In PHP, variables can be declared anywhere in the


script.
 The scope of a variable is the part of the script where
the variable can be referenced/used.
 PHP has three different variable scopes:
 local
 global
 static

Mr. Bilal Sadique (USA)


Local and Global Scope
24

 A variable declared outside a function has a


GLOBAL SCOPE and can only be accessed outside a
function.
 A variable declared within a function has a LOCAL
SCOPE and can only be accessed within that
function.
 The following example tests variables with local and
global scope:

Mr. Bilal Sadique (USA)


Local and Global Scope
25

PHP Source Code Result

<html><body>
<?php Test variables inside the
$x=5; // global scope
function:
function myTest(){
$y=10; // local scope Error on Server
echo "<p>Test variables inside the
function:</p>"; Variable y is: 10
echo "Variable x is: $x";
echo "<br>";
echo "Variable y is: $y";
}
myTest();
?>
</body></html>

Mr. Bilal Sadique (USA)


PHP The global Keyword
26

 The global keyword is used to access a global variable


from within a function.
 To do this, use the global keyword before the
variables (inside the function):

Mr. Bilal Sadique (USA)


Global Keyword
27

PHP Source Code Result

<html><body>
<?php Test variables inside the
$x=5; // global scope
function:
function myTest(){
$y=10; // local scope Variable x is: 5
global $x;
echo "<p>Test variables inside the Variable y is: 10
function:<p>";
echo "Variable x is: $x";
echo "<br>";
echo "Variable y is: $y";
}
myTest();
?>
</body></html>

Mr. Bilal Sadique (USA)


PHP The static Keyword
28

 Normally, when a function is completed/executed,


all of its variables are deleted. However, sometimes
we want a local variable NOT to be deleted. We need
it for a further job.
 To do this, use the static keyword when you first
declare the variable:

Mr. Bilal Sadique (USA)


Static Keyword
29

PHP Source Code Result

<html><body>
<?php 0
function myTest() {
static $x=0;
1
echo $x;
$x++; 2
}
myTest();
echo "<br>";
3
myTest();
echo "<br>"; 4
myTest();
echo "<br>";
myTest();
echo "<br>";
myTest();
?> </body></html>

Mr. Bilal Sadique (USA)

You might also like