Chapter 3 Introduction to PHP. Incorporating PHP Within HTML By default, PHP documents end with the extension.php files ending with.htm or.html to also.

Slides:



Advertisements
Similar presentations
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Advertisements

Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Nael Alian Introduction to PHP
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Variables, Operators and Data Types. By Shyam Gurram.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
1 JavaScript in Context. Server-Side Programming.
1 Working with Data Types and Operators. 2 Using Variables and Constants The values stored in computer memory are called variables The values, or data,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
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.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
What is PHP? IDIA Fall 2014 Bridget M Blodgett.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Introduction to PHP Advanced Database System Lab no.1.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
Week 4 PHP H ypertext P reprocessor Reference : Official Site :
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Strings, output, quotes and comments
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
1 JavaScript in Context. Server-Side Programming.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
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,
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
11 – Introduction to PHP(1) Informatics Department Parahyangan Catholic University.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Introduction to PHP and MySQL (Creating Database-Driven Websites)
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
PHP using MySQL Database for Web Development (part II)
Chapter 6 JavaScript: Introduction to Scripting
ITM 352 Data types, Variables
CHAPTER 5 SERVER SIDE SCRIPTING
PHP 5 Syntax.
Exploring JavaScript Ch 14
PHP Introduction.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
PHP an introduction.
Presentation transcript:

Chapter 3 Introduction to PHP

Incorporating PHP Within HTML By default, PHP documents end with the extension.php files ending with.htm or.html to also get parsed by the PHP processor To trigger the PHP commands, you need to learn a new tag. The first part is:

Calling the PHP Parser A small PHP “Hello World” program might look like <?php echo "Hello world"; ?> all the examples from this book have been archived onto a specially created companion website at

Using Comments There are two ways in which you can add comments // This is a comment after a line of code $x += 10; // Increment $x by 10 When you need multiple-line comments <?php /* This is a section of multiline comments which will not be interpreted */ ?>

Basic Syntax Semicolons $x += 10; You must place a $ in front of all variables <?php $mycounter = 1; $mystring = "Hello"; $myarray = array("One", "Two", "Three"); ?>

Understanding Variables String variables $username = "Fred Smith"; <?php // test1.php $username = "Fred Smith"; echo $username; echo " "; $current_user = $username; echo $current_user; ?>

Numeric variables $count = 17; to store the number 17 in the variable $count $count = 17.5; a floating-point number (containing a decimal point); Arrays $team = array('Bill', 'Joe', 'Mike', 'Chris', 'Jim'); Two-dimensional arrays <?php $oxo = array(array('x', '', 'o'), array('o', 'o', 'x'), array('x', 'o', '' )); ?>

Variable naming rules four rules: Variable names must start with a letter of the alphabet or the _ (underscore) character. Variable names can contain only the characters: a-z, A- Z, 0-9, and _ (underscore). Variable names may not contain spaces. If a variable must comprise more than one word it should be separated with the _ (underscore) character. (e.g., $user_name). Variable names are case-sensitive. The variable $High_Score is not the same as the variable $high_score.

Operators Operators are the mathematical, string, comparison, and logical commands such as plus, minus, times, and divide. PHP looks a lot like plain arithmetic; for instance, the following statement outputs 8: echo 6 + 2;

Arithmetic operators

Assignment operators

Comparison operators

Logical operators

Variable Assignment The syntax to assign a value to a variable is always variable = value. Or, to reassign the value to another variable, it is other variable = variable. Variable incrementing and decrementing String concatenation uses the period (.) to append one string of characters to another. The simplest way to do this is as follows: echo "You have ". $msgs. " messages.";

Multiple-Line Commands Example 3-6. A multiline string echo statement <?php $author = "Alfred E Newman"; echo "This is a Headline This is the first line. This is the second. Written by $author."; ?>

Variable Typing Variables do not have to be declared before they are used, and that PHP always converts variables to the type required by their context when they are accessed.

Constants Constants are similar to variables, holding information to be accessed later, except that they are what they sound like—constant

Echo and print Commands echo cannot be used as part of a more complex expression, whereas print can $b ? print "TRUE" : print "FALSE"; The question mark is simply a way of interrogating whether variable $b is true or false. Whichever command is on the left of the following colon is executed if $b is true, whereas the command to the right is executed if $b is false

Functions A simple function declaration <?php function longdate($timestamp) { return date("l F jS Y", $timestamp); } ?>

Global variables To declare a variable as having global scope, use the keyword global

A function using a static variable <?php function test() { static $count = 0; echo $count; $count++; } ?>

PHP’s superglobal variables