PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.

Slides:



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

Everyday Italian Giada De Laurentiis Harry Potter J K. Rowling Learning XML Erik T. Ray CSCI 305 Introduction to Database.
Objectives Using functions to organize PHP code
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.
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.
Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.
Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
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.
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.
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.
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.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Nael Alian Introduction to PHP
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
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.
PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
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.
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.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
PHP: A RRAYS, S TRINGS, AND F ILES CSCI 297 Scripting Languages - Day Three.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
CIS166AE : PHP Web Scripting Rob Loy. Tonight’s Agenda Housekeeping items Housekeeping items PHP basics PHP basics Student connection to server Student.
Introduction to Web Programming. Introduction to PHP What is PHP? What is a PHP File? What is MySQL? Why PHP? Where to Start?
PHP Open source language for server-side scripting Works well with many databases (e.g., MySQL) Files end in.php,.php3 or.phtml Runs on all major platforms.
PHP - 1h. How it works Client requests document Server loads document in memory Server processes document with relevant module (PHP) Server sends XHTML.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
1 PHP Introduction Chapter 1. Syntax and language constructs.
CS Class 08 Today  Exercises  Nested loops  for statement  Built-in functions Announcements  Homework #3, group solution to in-class.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
COP 3813 Intro to Internet Computing Prof. Roy Levow Lecture 4 JavaScript.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
Chap 2 – Getting Started COMP YL Professor Mattos.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
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.
Introduction to PHP 1.What is PHP? What Is PHP?  php: hypertext preprocessor  Server-side scripting language—like ASP—scripts are executed on server.
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,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP using MySQL Database for Web Development (part II)
More Selections BIS1523 – Lecture 9.
* Lecture 5 PHP Basics * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.
PHP Intro/Overview Bird Book pages 1-11,
Basics.
Intro to PHP.
PHP an introduction.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two

Topics for Today 1.Comments 2.Variables 3.Output and Input 4.Math Operators and Logic Operators 5.Selection 6.Iteration 7.Functions and Parameters

Comments PHP: Same as C++ // this is a comment /* all of this is comments */ HTML Comment Tag

Variables $Variable Names start with $, no weird characters, yadda yadda No need to declare variables o Warning: a compiler can act as a helpful spell checker. But PHP will not find this error: $aardvark = 15; if ($aardvrak < 50) Weak Typing o So, this is okay $bob = 0.0; $bob = "Hello World"; Type Casting (same as C++) $bob = (float) $joe;

Output The equivalent of C++'s cout is echo. Output variable contents: echo $cnt; Output a string: echo "Hello World"; Concatenate two items:. echo "Hello ". $name; There is no endln: echo " \n";

Output Outputting several lines: <<< echo <<<theEnd theEnd;

Input Direct Input is Not Applicable PHP is for writing server scripts, not a GUI. Data is passed to your script via variables from the web server process. Data may also be inside a file or a database. o file IO is in 2 weeks o database IO is 2 nd half of course Browser Web Server PHP Script MySQL

Operators for Math and Logic same as C++ $A = $B + $C; $A++; $A += $B; if ($A == $B) if ($A != $B && $A != $C)

Misc Operators $files = `ls`; // directory listing into variable define ('MAX', 100); // constant exit; // kill the script if (is_numeric ($input)) // plus thousands more if (is_null ($input))

Selection (conditional statements) same as C++, mostly if (...) {... } else {... } if (…) … elseif (…) … else … : if (...): blah blah; yadda yadda; endif endif;

Selection switch ( $option ) { case "A": break; case "B":... default: } // C = larger of A and B ?: $C = ($A > $B) ? $A : $B; That "ternary" operator is the same as: if ($A > $B) $C = $A; else $C = $B;

Iteration (loops) while loops and for loops are the same as C++ for ($A = 1; $A <= 10; $A++) { echo $A. " "; }

Functions Returning One Value function fix_cap_lock ($string1, $string2) { $string1 = ucfirst(strtolower($string1)); $string2 = ucfirst(strtolower($string2)); return $string1. " ". $string2; } $A = "hElLo"; $B = "WORlD"; echo fix_cap_lock ($A, $B); //prints Hello World Notice: No types

Functions Returning an Array function fix_cap_lock ($string1, $string2) { $string1 = ucfirst(strtolower($string1)); $string2 = ucfirst(strtolower($string2)); return array ($string1, $string2); } $A = "hElLo"; $B = "WORlD"; $C = fix_cap_lock ($A, $B); echo $C[0]. " ". $C[1];

Functions Pass by Reference && function fix_cap_lock (&$string1, &$string2) { $string1 = ucfirst(strtolower($string1)); $string2 = ucfirst(strtolower($string2)); } $A = "HeLlO"; $B = "WORlD"; fix_cap_lock ($A, $B); echo $A. " ". $B; // prints Hello World

Homework Write a for loop that will print the next seven dates, starting with today. Format = Tue Aug 27th see table 21.1 on page 470 for date() formatting codes Note that time() returns seconds since 1970.