PHP – An Introduction Albert Morita – UCR Libraries Systems Dept. December 9, 2004 Version 2.0.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
CMS (Content Management System And Wordpress) Presented By: Syed Arshad Sultan UI Developer – w3maestro.co.uk PHP & MySQL.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
PHP – An Introduction.
PHP/MySQL Tutorial Nguyễn Quang Hùng
Software Freedom Day th September 2007 Asia Pacific Institute of Information Technology Colombo, Sri Lanka. Nazly Ahmed Scripting The Web.
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.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
May 11, 2011 PHP Hypertext Preprocessor. What is the technology? ✤ Server side scripting and programming language. ✤ Can be embedded in HTML ✤ Free and.
By Brian Patterson & Amanda Perez. PHP was originally created to maintain his personal homepage, hence the name PHP. Development began in 1994 and was.
May 11, 2011 PHP Hypertext Preprocessor. What is the technology? ✤ Server side scripting and programming language. ✤ Can be embedded in HTML ✤ Free and.
PHP Scripting Language. Introduction “PHP” is an acronym for “PHP: Hypertext Preprocessor.” It is an interpreted, server-side scripting language. Originally.
WHAT IS PHP PHP is an HTML-embedded scripting language primarily used for dynamic Web applications.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
PHP PHP: Hypertext Preprocessing Matt Murphy & Dublas Portillo.
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
PHP PHP: Hypertext Preprocessing. What is PHP? PHP is a server-side scripting language designed specifically for the Web. An open source language PHP.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
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”
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 03.
PHP HYPERTEXT: PREPROCESSOR By: Justin T. Pleva. WHAT IS PHP?  General purpose  Server-side web development  Console application.
What is PHP PHP (officially "PHP: Hypertext Preprocessor") is a server-side HTML-embedded scripting language –means that code does not need to be compiled.
PHP - Hypertext Preprocessor Yaron Benita De Paul University.
COMP Week 5 Dr. Chunbo Chu. Agenda 1. Brief History of PHP 2. Basics 3. Advanced.
ITD 3194 Web Application Development Chapter 4: Web Programming Language.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Languages in WEB Presented by: Jenisha Kshatriya BCM SS09.
PHP was created by Rasmus Lerdorf in It was initially server-side, traffic tracking script. PHP 2 (1995) Added database support, file uploads, regular.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
PHP Professor Waterman. Agenda What is PHP Versions HTML Dynamic Web sites Interactive Web Sites Installing PHP Transfer pages to a Web hosting service.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP PHP: Hypertext Preprocessing Preston Brinks and Sean McKenzie.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
Nael Alian Introduction to PHP
PHP With Oracle 11g XE By Shyam Gurram Eastern Illinois University.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
Modified from Moseley ’s sli desWeb Applications Development. Lecture 5 Slide 1 Lecture 5: Introduction to PHP Instructor: Dr. Mohammad Anwar Hossain.
Introduction to PHP and MySQL Kirkwood Center for Continuing Education By Fred McClurg, © Copyright 2015, Fred McClurg, All Rights.
PHP OVERVIEW. C ONTENT Introduction of PHP History and development Basics of PHP programming.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
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.
WEB DEVELOPMENT WITH PHP/MYSQL. WEB DEVELOPMENT COURSE HAS DIFFERENT NAME IN DIFFERENT INSITUTES, THIS IS A CORE COURSE FOR BS/MS STUDENTS. THIS IS ALSO.
Yasar Hussain Malik - NISTE. PHP Origins Rasmus Lerdorf PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP Hypertext Processor’ Other key.
PHP Introduction PHP is a server-side scripting language.
1 PHP Pattadon Sintusak ID PHP Programmingintroduction2 Content History of PHP What’s PHP? Purpose of PHP Structure of PHP Language Reference.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
 Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript.
Company LOGO In the Name of Allah,The Most Gracious, The Most Merciful King Khalid University College of Computer and Information System Web pages Development.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
PHP stands for …….. “PHP Hypertext Pre-processor” and is a server-side scripting language like ASP. PHP scripts are executed on the server PHP supports.
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
PHP Basics and Syntax Lesson 3 ITBS2203 E-Commerce for IT.
Introduction to PHP and MySQL – Creating Database-Driven Websites
Albert Morita – UCR Libraries Systems Dept.
A PRESENTATION ON (IN PHP,CSS,HTML)
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.
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 PHP STAND FOR HYPERTEXT PRE-PROCESSOR. PHP PHP PHP STAND FOR HYPERTEXT PRE-PROCESSOR.
Albert Morita – UCR Libraries Systems Dept.
PHP Introduction.
IntroductionToPHP Static vs. Dynamic websites
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
Introduction to PHP.
Presentation transcript:

PHP – An Introduction Albert Morita – UCR Libraries Systems Dept. December 9, 2004 Version 2.0

Agenda 1. Brief History of PHP 2. Getting started 3. Examples

Brief History of PHP PHP (PHP: Hypertext Preprocessor) was created by Rasmus Lerdorf in It was initially developed for HTTP usage logging and server-side form generation in Unix. PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables, arrays, recursive functions, conditionals, iteration, regular expressions, etc. PHP 3 (1998) added support for ODBC data sources, multiple platform support, protocols (SNMP,IMAP), and new parser written by Zeev Suraski and Andi Gutmans. PHP 4 (2000) became an independent component of the web server for added efficiency. The parser was renamed the Zend Engine. Many security features were added. PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for interoperability with Web Services, SQLite has been bundled with PHP

Brief History of PHP As of August 2004, PHP is used on 16,946,328 Domains, 1,348,793 IP Addresses This is roughly 32% of all domains on the web.

Why is PHP used? 1.Easy to Use Code is embedded into HTML. The PHP code is enclosed in special start and end tags that allow you to jump into and out of "PHP mode". Example

Why is PHP used? 2.Cross Platform Runs on almost any Web server on several operating systems. One of the strongest features is the wide range of supported databases Web Servers: Apache, Microsoft IIS, Caudium, Netscape Enterprise Server Operating Systems: UNIX (HP-UX,OpenBSD,Solaris,Linux), Mac OSX, Windows NT/98/2000/XP/2003 Supported Databases: Adabas D, dBase,Empress, FilePro (read- only), Hyperwave,IBM DB2, Informix, Ingres, InterBase, FrontBase, mSQL, Direct MS-SQL, MySQL, ODBC, Oracle (OCI7 and OCI8), Ovrimos, PostgreSQL, SQLite, Solid, Sybase, Velocis,Unix dbm

Why is PHP used? 3.Cost Benefits PHP is free. Open source code means that the entire PHP community will contribute towards bug fixes. There are several add-on technologies (libraries) for PHP that are also free. PHP SoftwareFree PlatformFree (Linux) Development ToolsFree PHP CoderPHP Coder, jEditjEdit

Getting Started 1.How to escape from HTML and enter PHP mode PHP parses a file by looking for one of the special tags that tells it to start interpreting the text as PHP code. The parser then executes all of the code it finds until it runs into a PHP closing tag. Starting tagEnding tagNotes <?php?>Preferred method as it allows the use of PHP with XHTML <??>Not recommended. Easier to type, but has to be enabled and may conflict with XML ?>Always available, best if used when FrontPage is the HTML editor <%>Not recommended. ASP tags support was added in PHP CODE HTML

Getting Started 2.Simple HTML Page with PHP The following is a basic example to output text using PHP. My First PHP Page Copy the code onto your web server and save it as “test.php”. You should see “Hello World!” displayed. Notice that the semicolon is used at the end of each line of PHP code to signify a line break. Like HTML, PHP ignores whitespace between lines of code. (An HTML equivalent is )

Getting Started 3.Using conditional statements Conditional statements are very useful for displaying specific content to the user. The following example shows how to display content according to the day of the week. <?php $today_dayofweek = date(“w”); if ($today_dayofweek == 4){ echo “Today is Thursday!”; } else{ echo “Today is not Thursday.”; } ?>

Getting Started 3.Using conditional statements The if statement checks the value of $today_dayofweek (which is the numerical day of the week, 0=Sunday… 6=Saturday) If it is equal to 4 (the numeric representation of Thurs.) it will display everything within the first { } bracket after the “if()”. If it is not equal to 4, it will display everything in the second { } bracket after the “else”. <?php $today_dayofweek = date(“w”); if ($today_dayofweek == 4){ echo “Today is Thursday!”; } else{ echo “Today is not Thursday.”; } ?>

Getting Started 3.Using conditional statements If we run the script on a Thursday, we should see: “Today is Thursday”. On days other than Thursday, we will see: “Today is not Thursday.” <?php $today_dayofweek = date(“w”); if ($today_dayofweek == 4){ echo “Today is Thursday!”; } else{ echo “Today is not Thursday.”; } ?>

Examples PHP is a great way to implement templates on your website. How to implement a simple page counter

Examples Step 1: Universal header and footer in a single file Create a file called header.php. This file will have all of the header HTML code. You can use FrontPage/Dreamweaver to create the header, but remember to remove the closing and tags. UCR Webmaster Support Group Page Title

Examples Step 2: Universal header and footer in a single file Next, create a file called footer.php. This file will have all of the footer HTML code. UC Riverside Department

Examples Step 3: Universal header and footer in a single file This is the basic template that you will use on all of the pages. Make sure you name the files with a.php extension so that the server will process the PHP code. In this example, we assume the header and footer files are located in the same directory. <?php // header include(“header.php”); ?> Insert content here! <?php // footer include(“footer.php”); ?>

Examples Benefits: - Any changes to header or footer only require editing of a single file. This reduces the amount of work necessary for site maintenance and redesign. - Helps separate the content and design for easier maintenance Page 1 Content Page 5 Content Page 3 Content Page 2 Content Page 4 Content Header Footer

Examples Step 1: Simple Page Counter Download the counter file webcounter.txt onto your machinewebcounter.txt Upload the webcounter.txt file onto your web server (via FTP, WinSCP, etc) Change the file permissions of the webcounter.txt file to 777 to allow the counter file to be updated.

Examples Step 2: Simple Page Counter Copy this code into a page where you want a counter. <?php $COUNTER_FILE = “webcounter.txt"; if (file_exists($COUNTER_FILE)) { $fp = fopen("$COUNTER_FILE", "r+"); flock($fp, 1); $hits = fgets($fp, 4096); $hits += 1; fseek($fp,0); fputs($fp, $hits); flock($fp, 3); fclose($fp); } ?>

Examples Step 3: Simple Page Counter Next, output the counter value using PHP. Copy this line after the main block of code. This page has been viewed times. That’s it! The result should look something similar to:

Examples Step 3: Simple Page Counter You can change the text around the tags to your liking. visitors. This example shows 1.How to escape from HTML and enter PHP mode 2.How to output variables onto the screen using PHP

Examples 2.How to output variables using PHP Echo is the common method in outputting data. Since it is a language construct, echo doesn’t require parenthesis like print(). Output Text Usage: // prints out Hello World Output the value of a PHP variable: // prints out the number of hits Echo has a shortcut syntax, but it only works with the “short open tag” configuration enabled on the server.

Examples 3.Other uses with echo() Automatically generate the year on your pages. This will print out ©2004 UC Riverside. © UC Riverside You will need to escape any quotation marks with a backslash.

Additional Resources PHP Manual PHP Tutorial PHP Coder JEdit PHP's creator offers his thoughts on the PHP phenomenon, what has shaped and motivated the language, and where the PHP movement is heading Hotscripts – A large number of PHP scripts can be found at:

Additional Information Some of the new functions added in version 5: Arrays: array_combine() - Creates an array by using one array for keys and another for its values array_combine() array_walk_recursive() - Apply a user function recursively to every member of an arrayarray_walk_recursive() Date and Time Related: idate() - Format a local time/date as integeridate() date_sunset() - Time of sunset for a given day and locationdate_sunset() date_sunrise() - Time of sunrise for a given day and locationdate_sunrise() time_nanosleep() - Delay for a number of seconds and nano secondstime_nanosleep() Strings: str_split() - Convert a string to an arraystr_split() strpbrk() - Search a string for any of a set of charactersstrpbrk() substr_compare() - Binary safe optionally case insensitive comparison of two strings from an offset, up to length characterssubstr_compare() Other: php_check_syntax() - Check the syntax of the specified filephp_check_syntax() php_strip_whitespace() - Return source with stripped comments and whitespacephp_strip_whitespace()