PHP 5 Syntax.

Slides:



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

Outline What Is Function ? Create Function Call Function Parameters Functions Function Returning Values PHP Variable Scopes Passing by Reference Vs Value.
Php. What is PHP? PHP is an acronym for "PHP Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
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.
Copyright © Curt Hill PhP History and Introduction.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
INTERNET APPLICATION DEVELOPMENT For More visit:
Nael Alian Introduction to PHP
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
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.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
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.
Introduction to Web Programming. Introduction to PHP What is PHP? What is a PHP File? What is MySQL? Why PHP? Where to Start?
Comments in PHP In PHP, we use // to make a singleline comment or /* and */ to make a large comment block. Comment is a part of your PHP code that will.
Strings, output, quotes and comments
JavaScript Syntax, how to use it in a HTML document
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Python Let’s get started!.
PHP Variables.  Variables are "containers" for storing information. How to Declare PHP Variables  In PHP, a variable starts with the $ sign, followed.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
 A PHP script can be placed anywhere in the document.  A PHP script starts with  The default file extension for PHP files is ".php".  A PHP file normally.
FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD.
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.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
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.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
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,
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.
CGS 3066: Web Programming and Design Spring 2016 PHP.
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
Java Script Introduction. Java Script Introduction.
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
CHAPTER 5 SERVER SIDE SCRIPTING
เอกสารประกอบการบรรยายรายวิชา Web Technology
Introduction to Web programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Variables, Expressions, and IO
PHP Rasmus Lerdorf.
My First Web Page document.write("" + Date() + ""); To insert.
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
PHP Variables 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.
Elements of the PHP Programming Environment
PHP Introduction.
Intro to PHP & Variables
PHP.
Basics.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Basics (Cont...).
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
Tutorial 10: Programming with javascript
PHP an introduction.
Web Programming and Design
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Scope Rules.
Introduction to scripting
Presentation transcript:

PHP 5 Syntax

A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?> <?php // PHP code goes here ?>

The default file extension for PHP files is ".php". A PHP file normally contains HTML tags, and some PHP scripting code. <!DOCTYPE html> <html> <body> <h1>My first PHP page</h1> <?php echo "Hello World!"; ?> </body> </html>

Comments in PHP A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is editing the code! Comments are useful for: To let others understand what you are doing - Comments let other programmers understand what you were doing in each step (if you work in a group) To remind yourself what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code

<. DOCTYPE html> <html> <body> < <!DOCTYPE html> <html> <body> <?php // This is a single line comment # This is also a single line comment /* This is a multiple lines comment block that spans over more than one line */ ?> </body> </html>

PHP Case Sensitivity <!DOCTYPE html> <html> <body> <?php ECHO "Hello World!<br>"; echo "Hello World!<br>"; EcHo "Hello World!<br>"; ?> </body> </html>

However; 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): <!DOCTYPE html> <html> <body> <?php $color="red"; echo "My car is " . $color . "<br>"; echo "My house is " . $COLOR . "<br>"; echo "My boat is " . $coLOR . "<br>"; ?> </body> </html> My car is red My house is  My boat is 

PHP Variables 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)

Creating (Declaring) PHP Variables PHP has no command for declaring a variable. A variable is created the moment you first assign a value to it: <?php $txt="Hello world!"; $x=5; $y=10.5; ?> Hello world! 5 10.5

PHP Variables Scope 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

Local and Global Scope 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:

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

PHP The global Keyword 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): <?php $x=5; $y=10; function myTest() {   global $x,$y;   $y=$x+$y; } myTest(); echo $y; // outputs 15 ?> 15

PHP 5 echo and print Statements There are some differences between echo and print: echo - can output one or more strings print - can only output one string, and returns always 1 Tip: echo is marginally faster compared to print as echo does not return any value.

The PHP echo Statement echo is a language construct, and can be used with or without parentheses: echo or echo(). Display Strings The following example shows how to display different strings with the echo command (also notice that the strings can contain HTML markup): Example <?php echo "<h2>PHP is fun!</h2>"; echo "Hello world!<br>"; echo "I'm about to learn PHP!<br>"; echo "This", " string", " was", " made", " with multiple parameters."; ?>

The PHP print Statement print is also a language construct, and can be used with or without parentheses: print or print(). Display Strings The following example shows how to display different strings with the print command (also notice that the strings can contain HTML markup): <?php print "<h2>PHP is fun!</h2>"; print "Hello world!<br>"; print "I'm about to learn PHP!"; ?>