Download presentation
Presentation is loading. Please wait.
Published byDominick Gordon Modified over 6 years ago
1
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Lecture 3
2
What is PHP? http://theopensourcery.com/phpover.htm
Server-side interpreter which is Open Source and free Growing number of PHP web applications Start at PHP Resources Provides familiar syntax to C, Perl and Java developers Fast connections to popular databases Fast native connections to the Open Source MySQL database Runs reliably on Windows, Linux and Mac servers and clients Web pages run reliably on all the popular browsers Associative arrays are very useful for UI and database apps Object oriented classes are easy to understand Links to PDF, SWF, XML, Java, etc, etc.
3
Home site: HOME Site: Stats http://www.php.net/
Usage:
4
XAMPP In my examples XAMPP has been installed in: Apache root:
c:\xampp Apache root: C:\xampp\htdocs directed to the Apache root Put web files into the Apache root
5
Testing PHP php –v XAMPP in Windows
If php is installed and configured it will return the version number XAMPP in Windows Sets environment Run from “shell”
6
Testing apache/php http://localhost Create simple test webpage:
Will show XAMPP home page Uses the “magic” of the index.php default Create simple test webpage: Figure 1-2 on page 7 of Spring into PHP5 Save in c:/xampp/htdocs as ajktest1.php Default root for XAMPP Apache install Mixture of HTML and PHP Will display php installation information
7
Mixing HTML and PHP Can mix HTML and php code! Source: to view:
c:\xampp\htdocs\PHPBookExamples\ch01\phphtml.php to view:
8
Some php Basics Interpreted Language
All commands must be terminated with a “;” Contrast that to JavaScript Weakly typed language Data is interpreted for best type Programmer must use care in storing and retrieving data
9
Printing ECHO... ECHO... ECHO... ECHO... ECHO...
Sends the quoted text to the stdout echo “This is a test”;
10
Special Print Characters (escape sequences)
\n Newline \r Carriage return \t Tab \\ Prints a \ \$ Prints a $ \” Prints a “ \0 to \777 Prints a character based on the octal value \x0 to \xFF Prints a character based on the hexadecimal value
11
Quote notes Single and Double quote have similar but different uses:
Single Quotes: “ ' “ Literal storage of the string Double Quotes: “ " “ Allows “interpretation” escape sequences values for imbedded variables (eg. $value)
12
Command line php can be used from a command line
Must be in a “path” or in the directory Windows XAMPP: Use the Shell button to set environment
13
Comments Scripts must be maintainable!!!! Single line: // or #
Use comments to document the code Single line: // or # echo “test1”; echo “test2”; // this is a comment echo “test3”; # this is another comment One or more lines: /* … */ echo “test2”; /* this starts a comment that continues on the next line and ends here */ echo “test3”;
14
Variables - Names Variables Begin with a $ Second character may be:
a letter - or - an underscore Third and following characters may be: letters numbers underscores No practical length restriction
15
Variables - Types php is a weakly typed language
Do not need to declare variable type Programmers responsibility to put and retrieve the correct type of data php will convert data types as needed
16
Variables - Assigning Basic assignment operator is the =
$var1 = 255; // var1 is an integer $var2 = “Test”; // var2 is a string $var3 = 3.1; // var3 is a float $var4 = TRUE; // var4 is a boolean
17
Variables: Interpolating
Interpolating variables in string php will replace variables in strings with their values String must be in double quotes Example $dogs = 2; echo “There are $dogs in the yard.”; Curly braces will allow the variable to be parsed and placed exactly in text (no spaces)
18
Variable variables Variables may contain the name of variables!
Use $$varname to access To use: Declare your variables $dogname = “Fido”; $catname = “Felix”; Assign variable name to your “variable variable” $petname = “dogname”; Use the “variable variable” – note the use of $$ echo “Your pet name is “, $$petname; Example: ajkExamples/ch01/varvar.php
19
Constants php makes creating constants easy: define()
define(“pi”, ); define(“fname”, “Jack”); define(“lname”, “Spratt”);
20
Keywords endif endswitch endwhile extends final (as of PHP 5) for
PHP Keywords abstract (as of PHP 5) and array() as break case catch cfunction (PHP 4 only) class clone const continue declare default do else elseif enddeclare endfor endforeach namespace (as of PHP 5.3) new old_function (PHP 4 only) or private (as of PHP 5) protected public static switch throw try use var while xor endif endswitch endwhile extends final (as of PHP 5) for foreach function global goto (as of PHP 5.3) if implements interface instanceof
21
Keywords Compile-time constants Language constructs die()
__CLASS__ __DIR__ (as of PHP 5.3) __FILE__ __FUNCTION__ __METHOD__ __NAMESPACE__ Language constructs die() echo() empty() exit() eval() include() include_once() isset() list() require() require_once() return() print() unset()
22
Data Types Boolean Integer Float String Array Object Resourse NULL
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.