FMI-PLOVDIV Web Dynamic Applications

Slides:



Advertisements
Similar presentations
Introduction to PHP Dr. Charles Severance
Advertisements

1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
Outline Java program structure Basic program elements
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
Expressions and Control Flow in PHP Dr. Charles Severance
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
PHP Workshop ‹#› PHP: The Basics. PHP Workshop ‹#› What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor”
CSC 405: Web Application And Engineering II 2.1 Web Programming with PHP Introduction to Web programming Introduction to Web programming The programming.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
An Introduction to PHP The University of Tennessee at Chattanooga C. Daniel Chase “An introduction to basic PHP use with a focus on the power of dynamic.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
PHP Arrays Dr. Charles Severance
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Strings, output, quotes and comments
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
PHP Workshop ‹#› أطلق إبداعك 2 أطلق إبداعك 2 مدرس معتمد من مركز زووم PHP: The Basics.
CSC 405: Web Application Engineering II 2.1 Web Programming with PHP Introduction to Web programming Introduction to Web programming The programming language.
Expressions and Control Flow in PHP. Expressions Expressions evaluate to a value. The value can be a string, number, boolean, etc... Expressions often.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
PHP Arrays Dr. Charles Severance
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Introduction to Dynamic Web Content Chapter 1 Dr. Charles Severance To be used in assocition with the book: PHP, MySql, and JavaScript by Robin Nixon.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
I NTRODUCTION TO PHP. PHP PHP is a server scripting language, and is a powerful tool for making dynamic and interactive Web pages quickly PHP is a widely-used,
Chapter 1.2 Introduction to C++ Programming
CGS 3066: Web Programming and Design Spring 2017
PHP Arrays Dr. Charles Severance
Expressions and Control Flow in PHP
Definition of the Programming Language CPRL
Chapter 1.2 Introduction to C++ Programming
Ruby: An Introduction Created by Yukihiro Matsumoto in 1993 (named after his birthstone) Pure OO language (even the number 1 is an instance of a class)
Chapter 1.2 Introduction to C++ Programming
CS 371 Web Application Programming
Introduction to PHP Dr. Charles Severance
PHP 5 Syntax.
Introduction to PHP Dr. Charles Severance
Lecture 2: Data Types, Variables, Operators, and Expressions
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Introduction to PHP Dr. Charles Severance
PHP Arrays Dr. Charles Severance
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
JavaScript Syntax and Semantics
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Expressions and Control Flow in PHP
Intro to PHP & Variables
Starting JavaProgramming
Introduction to C++ Programming
* Lecture 5 PHP Basics * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Units with – James tedder
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
elementary programming
Focus of the Course Object-Oriented Software Development
Zorah Fung University of Washington, Spring 2015
Javascript Chapter 19 and 20 5/3/2019.
PHP an introduction.
Chap 2. Identifiers, Keywords, and Types
PHP Language Basics.
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

FMI-PLOVDIV Web Dynamic Applications Introduction to PHP Nikolay Chochev Technical Trainers FMI-Plovdiv http://fmi-plovdiv.org © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

About the PHP Language Syntax is inspired by C Curly braces, semicolons, no signficant whitespace Syntax inspired by perl Dollar signs to start variable names, associative arrays Extends HTML to add segments of PHP within an HTML file.

Philosphy of PHP You are a responsible and intelligent programmer You know what you want to do Some flexibility in syntax is OK - style choices are OK Lets make this as convienent as possible Sometimes errors fail silently

<h1>Hello from Dr. Chuck's HTML Page</h1> <?php echo "Hi there.\n"; $answer = 6 * 7; echo "The answer is $answer, what "; echo "was the question again?\n"; ?> </p> <p>Yes another paragraph.</p>

<h1>Hello from Dr. Chuck's HTML Page</h1> <?php echo "Hi there.\n"; $answer = 6 * 7; echo "The answer is $answer, what "; echo "was the question again?\n"; ?> </p> <p>Yes another paragraph.</p>

PHP From the Command Line You can run PHP from the command line - the output simply comes out on the terminal It does not have to be part of a request-response cycle <?php echo("Hello World!"); echo("\n"); ?>

Key Words abstract and array() as break case catch class clone const continue declare default do else elseif end declare endfor endforeach endif endswitch endwhile extends final for foreach function global goto if implements interface instanceof namespace new or private protected public static switch $this throw try use var while xor http://php.net/manual/en/reserved.php

Variable Names Start with a dollar sign ($) followed by a letter or underscore, followed by any number of letters, numbers, or underscores Case matters $abc = 12; $total = 0; $largest_so_far = 0; abc = 12; $2php = 0; $bad-punc = 0; http://php.net/manual/en/language.variables.basics.php

Variable Name Weirdness Things that look like variables but are missing a dollar sign can be confusing $x = 2; $y = x + 5; print $y; $x = 2; y = $x + 5; print $x; 5 Parse error

Expressions 42 Completely normal like other languages ( + - / * ) More agressive implicit type conversion <?php $x = "15" + 27; echo($x); echo("\n"); ?> 42

Output <?php $x = "15" + 27; echo $x; echo("\n"); echo $x, "\n"; print $x; print "\n"; print($x); print("\n"); ?> echo is a language construct - can be treated like a function with one parameter. Without parenthesis, it accepts multiple parameters. print is a function - only one parameter but parenthesis are optional so it can look like a language construct

Conditional - if Hello World! Logical operators ( == != < > <= >= && || ! ) Curly braces <?php $ans = 42; if ( $ans == 42 ) { print "Hello world!\n"; } else { print "Wrong answer\n"; } ?> Hello World!

Whitespace does not matter <?php $ans = 42; if ( $ans == 42 ) { print "Hello world!\n"; } else { print "Wrong answer\n"; } ?> <?php $ans = 42; if ( $ans == 42 ) { print "Hello world!\n"; } else { print "Wrong answer\n"; } ?>

What Style do You Prefer? <?php $ans = 42; if ( $ans == 42 ) { print "Hello world!\n"; } else print "Wrong answer\n"; ?> <?php $ans = 42; if ( $ans == 42 ) { print "Hello world!\n"; } else { print "Wrong answer\n"; } ?> Aesthetics

Associative Arrays Like Python Dictonaries+Lists - but more powerful Can be key => value or simply indexed by numbers Ignore two-dimensional arrays for now...

Integer Indices There <?php $stuff = array("Hi", "There"); echo $stuff[1], "\n"; ?> There

Integer Indices World <?php $stuff = array(); $stuff[] = "Hello"; $stuff[] = "World"; echo $stuff[1], "\n"; ?> World

Integer Indices World <?php $stuff = array(); $stuff[2] = "Hello"; $stuff[9] = "World"; echo $stuff[9], "\n"; ?> World

Key / Value SI664 <?php $stuff = array("name" => "Chuck", "course" => "SI664"); echo $stuff["course"], "\n"; ?> SI664

Dumping an Array The function print_r() dumps out PHP data - it is used mostly for debugging <?php $stuff = array("name" => "Chuck", "course" => "SI664"); print_r($stuff); ?> Array ( [name] => Chuck [course] => SI664 )

Dumping an Array The function print_r() dumps out PHP data - it is used mostly for debugging <?php $stuff = array(); $stuff[2] = "Hello"; $stuff[9] = "World"; print_r($stuff); ?> Array ( [2] => Chuck [9] => SI664 )

var_dump .vs. print_r <?php $stuff = array("name" => "Chuck", "course" => "SI664"); var_dump($stuff); ?> array(2) { ["name"]=> string(5) "Chuck" ["course"]=> string(5) "SI664" } http://stackoverflow.com/questions/3406171/php-var-dump-vs-print-r

var_dump() is more verbose <?php $thing = FALSE; echo("One\n"); print_r($thing); echo("Two\n"); var_dump($thing); ?> One Two bool(false) http://stackoverflow.com/questions/3406171/php-var-dump-vs-print-r

Looping Through an Array <?php $stuff = array("name" => "Chuck", "course" => "SI664"); foreach($stuff as $k => $v ) { echo "Key=",$k," Val=",$v,"\n"; } ?> Key=name Val=Chuck Key=course Val=SI664

Variable Name Weirdness Things that look like variables but are missing a dollar sign as an array index are unpredictable.... $x = 5; $y = array("x" => "Hello"); print $y[x]; Hello

Strings / Different + Awesome String literals can use single quotes or double quotes The backslash (\) is used as an "escape" character Strings can span multiple lines - the newline is part of the string In double-quoted strings variable values are expanded Concatenation is the "." not "+" (more later) http://php.net/manual/en/language.types.string.php

Double Quote <?php echo "this is a simple string\n"; echo "You can also have embedded newlines in  strings this way as it is okay to do"; // Outputs: This will expand:  // a newline echo "This will expand: \na newline"; // Outputs: Variables do 12 $expand = 12; echo "Variables do $expand\n"; ?>

Single Quote <?php echo 'this is a simple string'; echo 'You can also have embedded newlines in  strings this way as it is okay to do'; // Outputs: Arnold once said: "I'll be back" echo 'Arnold once said: "I\'ll be back"'; // Outputs: This will not expand: \n a newline echo 'This will not expand: \n a newline'; // Outputs: Variables do not $expand $either echo 'Variables do not $expand $either'; ?> Single Quote

echo 'This is a test'; // This is a c++ style comment <?php     echo 'This is a test'; // This is a c++ style comment     /* This is a multi line comment        yet another line of comment */     echo 'This is yet another test';     echo 'One Final Test'; # This is a shell-style comment ?> http://php.net/manual/en/language.basic-syntax.comments.php

Summary This is a sprint through some of the unique language features of PHP