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

Week1 Ita2 Intro To PHP

This document provides an overview and introduction to PHP programming. It discusses what PHP is, how to set up an IDE and server, basic PHP syntax including variables, data types, echo/print statements, and quotes. It also covers the differences between client-side and server-side scripting, and examples of basic PHP structures like if/else statements, switch statements, while and for loops. Resources like W3Schools are recommended for further PHP study.

Uploaded by

Aakash Thawani
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)
53 views29 pages

Week1 Ita2 Intro To PHP

This document provides an overview and introduction to PHP programming. It discusses what PHP is, how to set up an IDE and server, basic PHP syntax including variables, data types, echo/print statements, and quotes. It also covers the differences between client-side and server-side scripting, and examples of basic PHP structures like if/else statements, switch statements, while and for loops. Resources like W3Schools are recommended for further PHP study.

Uploaded by

Aakash Thawani
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

ITA2

Week 1
PHP & Programming Intro

Setup & schedule


See study guide.

This week

What is PHP
IDE, server
PHP Syntax: variables, datatypes
Echo, print, quotes

Client- and server-side scripting


languages
Webserver

index.html

Browser
INTERNET

USER

SERVER

Client- en server-side
scripting languages
Webserver

Scripting Machine

Browser
INTERNET

USER

index.php
SERVER

Client- en server-side
scripting languages
Webserver

Scripting Machine

Browser
INTERNET

USER

index.php

Database

SERVER

What is PHP?

PHP: PHP Hypertext Pre-processor


its a server-side scripting language
its self contained
its platform independent
its open-source
Its modular
Its invisible to the end-user (?)

PHP Basic syntax

A PHP file has a .php extension


PHP code starts with <?php
PHP code ends with ?>
PHP in HTML or vice versa is possible
PHP looks a lot like C#, JAVA, C

Netbeans
IDE for PHP development
Also for debugging:
connects to webserver while PHP is
running.
Version control (SVN/GIT/Mercurial)
DEVelopment, TeST, PRoDuction.
Netbeans dir, xampp,athena

Code & Comment use


html)
<html>
<head>
<title>Page 1</title>
</head>
<body>
<?php
// print nice welcome message
echo Welcome at my course";
?>
</body>
</html>

(php in

Code & Comment use


php)
<?php
Echo "<html>"
Echo "<head>""
Echo " <title>Page 1</title>""
Echo "</head>""
Echo "<body>""
// print nice welcome message
Echo "Welcome at my course";
Echo "</body>"
Echo "</html>"
?>

(html in

Variables
All variables start with $
Names are case sensitive
Names can contain letters, digits or '_'
Names can not begin with a number
Variables can be declared in advance
Constants:
No $, just capitals
Define(MY_CONSTANT , 23);

Naming convention
variables
(Zend framework) standard
conventions:
Use camelCasing;
$someString, $aLongVariable
myFunctie

Do NOT use_ underscores


Names starting with a digit are NOT
allowed
Info: http://framework.zend.com/manual/en/coding-standard.naming-

Variable names
Valid or not?
variabele2
$variabele3
$4square
$the website
$the_website

Variable names
Valid or not?
variabele2
$variabele3
$4square
$the website
$the_website

wrong: misses dollar sign


valid
Wrong: starts with digit
Wrong: contains space
Valid ( rather not )

Echo, print and quotes


echo is used to show content on screen
echo "test";

print is almost the same; preferable echo


print "test" ;

Content in ' ' is not interpreted by PHP


(single quotes)
echo this is $directly done'; //$directly

Content in " " is interpreted (double quotes)


Escaping of symbols on HTML export \
(backslash)
echo "<a href=\"php.net\">php.net</a>\n";

Quotes
<?php
$wer =World2"; // declaring variable $wer
echo
echo
echo
echo
echo
echo
echo
echo
?>

"Hello world<br>\n";
'Hello world<br>\n';
"Hallo 'world'<br>\n";
'Hello "world"<br>';
"Hello \"world\"<br>\n";
'Hello \'world\'<br>';
"Hello $wer<br>\n";
'Hello $wer<br>\n';

Variables & datatypes:


unlike C#
<?php
$name
= "Period 5";
// a String
$amount
= 15;
// an Integer
$euroDollar
= 1.326
// a Float
$access
= false;
// a Boolean
$access
= 2.44;
// a float
$access
= "my text";
// a String
$names = array("john","me","joao"); // an array
?>
Find type with var_dump() method

Variables & datatypes:


unlike C#
Find type with var_dump() method

Expressions
Like C#:
$a = $b + $c;
$b++
$c = $a / $d; (whats the type here?)

Operators
<?php
echo "apple" . cake"; // result: applecake
?>

with a . you can concatenate


strings
<?php
$color = "red";
echo $color." car"; // result: red car
echo "$color car"; // result: red car
?>

Assignment operators
Assigning a value to a variable.
$studCount = 8;

// $studCount gets value 8

$shoeColor = yellow";

// $shoeColor gets value

yellow, but what type?

Comparison operators
Comparing 2 values (or variables) returns TRUE or
FALSE.
<
smaller than
<=
smaller than or equal to
>
bigger than
>=
bigger than or equal to
==
equal to
!=
not equal to / unequal to
=== identical to (equal to AND the same datatype)
!== not identical to (not equal to OR not the same
datatype)

Comparison operators
$a = 3;

$a
$a
$a
$a
$a

== $b;
== $c;
!= $c;
<= $c;
=== $b;

//
//
//
//

$b = "3";

$c = 5;

// is equal to (TRUE)
is equal to (FALSE)
is unequal to (TRUE)
is smaller or equal to (TRUE)
is equal to, not datatype (FALSE)

Selection: IF ELSEIF
ELSE
selection: IF watch carefully for curly
braces
$amount = 6.98;
if ( $amount <= 6.0 ) {
echo this product is not expensive";
}
elseif ( $amount <= 8.0 ) {
echo this product has an average price";
}
else {
echo this product is too expensive";
}

Selection: Switch
Mostly used for choosing among
alternatives
$language ="en";
switch ($language) {
case "en":
echo "English";
break;
case "nl":
echo Dutch";
break;
case "de":
echo German";
break;
default:
echo No language selected";
}

Iteration: While
As long as condition is TRUE, you execute
something.
while( condition ) {
commands;
}
$i = 0;
while( $i < 10 )
{
echo "\$i is now $i <br>";
$i++;
// i +1
}

Iteration: FOR
Looks like while , mostly used if amount of
loops is known.
for (initial expression; condition; loop-end
expression) {
commands;
}
for ( $i = 0; $i < 10; $i++ )
{
echo "\$i is now $i <br>";
}

Study
W3schools:
variables, echo/print, datatypes,
constants,
operators,if..else...elsif,switch,while,for.
OR (if you have the book):
Beginning PHP 5.3: chapter 3 & 4 +
chapter 1 & 2 (practical)

You might also like