Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Java Script Session1 INTRODUCTION.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
PHP Intro/Overview Squirrel Book pages Server-side Scripting Everything you need to know in one slide 1.Web server (with PHP “plug-in”) gets a.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
PHP: Introduction By Trevor Adams.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
PHP: Hypertext Processor Fred Durao
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.
NMD202 Web Scripting Week1. Contact Information – Lecturer is a part time member of staff. Students are encouraged to use.
PHP MOHAMMED SHURRAB TO MISS/ RASHA ATTALLAH. What is PHP? Stands for "PHP Hypertext Preprocessor" Server-side scripting language HTML-embedded Supports.
Advanced Web 2012 Lecture 4 Sean Costain PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
CISC474 - JavaScript 03/02/2011. Some Background… Great JavaScript Guides: –
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Shell Script Programming. 2 Using UNIX Shell Scripts Unlike high-level language programs, shell scripts do not have to be converted into machine language.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
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 - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
1 CS428 Web Engineering Lecture 20 Control Structures, Loops and Pointers File Uploading Function (PHP - III)
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
PHP Teresa Worner. What is it? PHP: Hypertext Preprocessor server-side scripting language open source cross-platform compatible with almost all servers.php.php3.phtml.
CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
CS 174: Web Programming September 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
PHP - 1h. How it works Client requests document Server loads document in memory Server processes document with relevant module (PHP) Server sends XHTML.
Introduction to PHP.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
הרצאה 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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
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.
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
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,
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
Introduction to Dynamic Web Programming
Web Database Programming Using PHP
DBW - PHP DBW2017.
PHP.
Web DB Programming: PHP
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
Programming PHP on the Server
PHP an introduction.
23 PHP.
Presentation transcript:

Just a Little PHP Programming PHP on the Server

Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control Statements Functions and Subroutines Macros and Preprocessor Commands I/O Statements Libraries External Tools (Compiler, debugger etc)

PHP like JavaScript is Embedded in Web Pages The difference is that a PHP file is executed by the Server BEFORE being sent to the client. Just like CGI. <?php //Your PHP goes here ?>

Comments // This is a single line comment /* This is a multiline comment just like C */ # works as a comment, just like the bash shell

Data Types PHP is a weakly typed language. Any variable can be any data type The available data types are: boolean number (integer and float) string array object

Variable Names To declare a scalar variable just use it. Variable names begin with a $, ie: $x=7; echo $counter; #Assignment - all variables preceded by $ #whether on the left or the right $x=$myValue*2

Using Quotes $x=‘The contents $var of this string are literally’; $y=“But $var is the value of the variable”; $z=`uptime`; #Run as a shell command, stored in $z $a=“Quoting in \$doubleQuotes \n ”;k

Constants Numeric: E x2A String: “Hello” ‘Nice Day’ Bob define(“MYCONSTANT”, 42); echo MYCONSTANT If a constant is not defined it stands for itself, ie: Bob. Otherwise it stands for its value. Constants should be ALLCAPS and do not use a $ before the name

Creating an Array $list[0] = 17; //This creates an array $list = array(1,2,3 4,5); //creates an indexed array $list = array(“Smith” => “Carpenter, “Jones”=> “Technician”, “Rajiv” => “Manager”); //Associative array $n=sizeof($list);

Operators Arithmetic: Regular C style operators = + - * / % += -= *= /= Relational: == != <> > = <= Note: “4” == 4 is True String: “a”. $b $a.=$b; Logical: && || !

Web Page Output echo “The size of my array is: “. $n; print “Hello World: “. $n; printf “There are %4d items in my array, %s\n”, $n, $name; printf uses the same format codes that C uses: %d (integer) %f (float) %x (hex) %s (string) (There is one new format code: %b - binary)

Dumping an Array print_r($anyArry); #The entire array is dumped to the screen

if/then/else if ($price 20) { printf “%10.2f is a reasonable price ”, $price; $total+=$price; } else echo “Try again!”;

switch switch($choice) { case 1: case ‘beer’: doSomething();... break; case ‘prezels: doSomethingElse();... break; default: echo “Unknown option”; }

Simple for loops for($i=1;$i<10;$i++) { $sum+=$i; echo “Running total is: “ + $sum + “ ”; } echo “Final total is: “ $sum;

Looping Through Associative Arrays foreach( $array as $key => $value) { echo “Key: “. $key echo “Value: “. $value; } Note: Associative Arrays and Indexed Arrays are the same thing. The key values for an indexed array are: 0, 1,

Functions in PHP function myFunction($arg1, $arg2, $arg3) { //Do some calculation ie: $result= ($arg1 + $arg2) % $arg3; return $result; }

Including a library of functions include (“myLibraryFile.php”); require(“myLibrary.php”); require_once(“myLibrary.php”); Use any of:

Debugging Php In the same directory as your php program, include the file php.ini: display_errors=on A missing quote may result in a blank web page. Test your program for syntax error on the command line where it will show up: $bash 3.2: php yourProg.php

Debugging Continued In every PHP program include the following as the very first commands: <?php ini_set(‘display_errors’,1); error_reporting(E_ALL);... ?> Strategies: Always comment your code FIRST Comment out blocks of code to isolate the error Narrow down syntax errors to a single line. Split complex lines into smaller stages Use echo and printf statements liberally

Important PHP VariablesPurpose $_GET, $_POST, $_COOKIE $_REQUEST Data sent between client and server. $_REQUEST includes all 3 $REMOTE_ADDRIP of the client $HTTP_REFERERPrevious Web Page $REQUEST_TIMEWhen page was requested (EPOCH time) $HTTP_USER_AGENTBrowser Info $_SERVERArray of Server related values

SQL Functions MYSQL FUNCTION CALLEXPLANATION mysql_error()Report on last error mysql_connect(host,user, pass)connects to database; returns a connection to the database mysql_selectdb(dbName)use specified schema $result=mysql_query(stmt)runs stmt against the database returns 0 to n rows for SELECT returns number of rows affected for INSERT, UPDATE or DELETE $row=mysql_fetch_array($resu lt) creates an associative array using column names as keys mysql_close($con)closes the database connection

SQL Functions Some PHP FunctionsEXPLANATION date(‘r’)The current date as a string time()current time die(message)print out a message and quit include(‘fileName’) require_once(‘fileName’); include an external PHP file – allows shared code and libraries header(‘attribute: value’)adds a header to the response

PHP Has A Rich Set of Library Functions

THE END