Fall 2004CSI 4118 -- University of Ottawa Introduction to PHP Basic principles and syntax.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Java Script Session1 INTRODUCTION.
Introduction to JavaScript
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
Everyday Italian Giada De Laurentiis Harry Potter J K. Rowling Learning XML Erik T. Ray CSCI 305 Introduction to Database.
BY: ALBERTO CABEZAS 4/19/2010. INTRODUCTION: PHP is considered today as one of the most famous scripting languages. PHP is widely used as a general purpose.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Guide To UNIX Using Linux Third Edition
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
PHP The Basic. Outline  History of PHP  What is PHP?  What does PHP code look like?  Apache Server.  Syntax PHP code.  Anatomy of a PHP Script.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
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”
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
PHP: Hypertext Processor Fred Durao
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
Copyright © Curt Hill PhP History and Introduction.
Introduction to Database. What is PHP? PHP == ‘PHP Hypertext Preprocessor’ Open-source, server-side scripting language Used to generate dynamic web-pages.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
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.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
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.
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.
Week 4 PHP H ypertext P reprocessor Reference : Official Site :
Introduction to PHP.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Workshop ‹#› أطلق إبداعك 2 أطلق إبداعك 2 مدرس معتمد من مركز زووم PHP: The Basics.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
PHP/MySQL Tutorial Introduction to Database Programming.
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.
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.
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,
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
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)
PHP for Server-Side Programming
Introduction to Dynamic Web Programming
Introduction to PHP “PHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be.
PHP (PHP: Hypertext Preprocessor)
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Introduction to PHP “PHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be.
PHP Introduction.
Intro to PHP & Variables
PHP.
Basics.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
PHP: Hypertext Preprocessor
PHP an introduction.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax

Fall 2004CSI 4118 – University of Ottawa What is PHP? PHP == ‘Hypertext Preprocessor’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP tags This allows the programmer to embed PHP scripts within HTML pages

Fall 2004CSI 4118 – University of Ottawa What is PHP (cont’d) Interpreted language, scripts are parsed at run-time rather than compiled beforehand Executed on the server-side Source-code not visible by client ‘View Source’ in browsers does not display the PHP code Plethora of built-in functions allow for fast development Compatible with many popular databases

Fall 2004CSI 4118 – University of Ottawa What does PHP code look like? Structurally similar to C/C++ Supports procedural and object-oriented paradigm (to some degree) All PHP statements end with a semi-colon Each PHP script must be enclosed in the reserved PHP tag <?php … ?>

Fall 2004CSI 4118 – University of Ottawa Comments in PHP Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */

Fall 2004CSI 4118 – University of Ottawa Variables in PHP PHP variables must begin with a “$” sign Case-sensitive ($Foo != $foo != $fOo) Global and locally-scoped variables Global variables can be used anywher Local variables restricted to a function or class Certain variable names reserved by PHP Form variables ($_POST, $_GET) Server variables ($_SERVER) Etc.

Fall 2004CSI 4118 – University of Ottawa Variable usage <?php $foo = 25;// Numerical variable $bar = “Hello”;// String variable $foo = ($foo * 7);// Multiplies foo by 7 $bar = ($bar * 7);// Invalid expression ?>

Fall 2004CSI 4118 – University of Ottawa Echo The PHP command ‘echo’ is used to output the parameters passed to it The typical usage for this is to send data to the client’s web-browser Syntax void echo (string arg1 [, string argn...]) In practice, arguments are not passed in parentheses since echo is a language construct rather than an actual function

Fall 2004CSI 4118 – University of Ottawa Echo example Notice how echo ‘5x5=$foo’ outputs $foo rather than replacing it with 25 Strings in single quotes (‘ ‘) are not interpreted or evaluated by PHP This is true for both variables and character escape-sequences (such as “\n” or “\\”) <?php $foo = 25;// Numerical variable $bar = “Hello”;// String variable echo $bar;// Outputs Hello echo $foo,$bar;// Outputs 25Hello echo “5x5=“,$foo;// Outputs 5x5=25 echo “5x5=$foo”;// Outputs 5x5=25 echo ‘5x5=$foo’;// Outputs 5x5=$foo ?>

Fall 2004CSI 4118 – University of Ottawa Functions Functions MUST be defined before then can be called Function headers are of the format Note that no return type is specified Unlike variables, function names are not case sensitive (foo(…) == Foo(…) == FoO(…)) function functionName($arg_1, $arg_2, …, $arg_n)

Fall 2004CSI 4118 – University of Ottawa Functions example <?php // This is a function function foo($arg_1, $arg_2) { $arg_2 = $arg_1 * $arg_2; return $arg_2; } $result_1 = foo(12, 3);// Store the function echo $result_1;// Outputs 36 echo foo(12, 3);// Outputs 36 ?>

Fall 2004CSI 4118 – University of Ottawa The Big Picture for Assignment 2 Learn about web-servers Learn about Apache Download / Installation Learn about PHP Download / Installation Configure Apache Modify and save the configuration file, then restart Learn about file I/O without the aid of SQL Design, write, and test scripts to solve Assignment 2

Fall 2004CSI 4118 – University of Ottawa Saving Data in Text Files PHP has built in functions for File I/O processing fopen (..), fwrite(..), fclose(..), fflush(..), file_get_contents(..) Using these pre-made functions, File I/O in PHP is similar to that of C General Flow: Open file Read data Modify data Write data Close file

Fall 2004CSI 4118 – University of Ottawa Saving Data in Text Files: Example <?php $filename = 'test.txt';/* Filename for writing. This is assumed to be in the same directory as the script */ $somecontent = "Add this to the file\n";// String to append to the file // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // Open the file in append mode ( ‘a’ ) so that the string being stored is written at the end of the // file rather than replacing the existing text if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to the opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?>

Fall 2004CSI 4118 – University of Ottawa For more information…