Presentation is loading. Please wait.

Presentation is loading. Please wait.

IST 221 Internet Concepts and Applications Introduction to PHP.

Similar presentations


Presentation on theme: "IST 221 Internet Concepts and Applications Introduction to PHP."— Presentation transcript:

1 IST 221 Internet Concepts and Applications Introduction to PHP

2 PHP, Hypertext Preprocessor A Server side HTML embedded scripting Language. A Server side HTML embedded scripting Language. An Alternative to perl-CGI, ASP, JSP and Cold Fusion. An Alternative to perl-CGI, ASP, JSP and Cold Fusion. PHP is similar to Javascript, but on the server side. PHP is similar to Javascript, but on the server side.

3 PHP Syntax The syntax and semantics of PHP are closely related to the syntax and semantics of JavaSscript and Perl The syntax and semantics of PHP are closely related to the syntax and semantics of JavaSscript and Perl PHP uses dynamic typing. PHP uses dynamic typing. PHP variable names are case sensitive PHP variable names are case sensitive PHP tag: PHP tag: Comments: #, // and /*…..*/ Comments: #, // and /*…..*/

4 PHP Primitives Variables: Integer, Double, String and Boolean. Variables: Integer, Double, String and Boolean. String literals are defined with either single(‘) or double (“) quotes. String literals are defined with either single(‘) or double (“) quotes. –‘The sum is : $sum’ –“The sum is : $sum” –Which format would take \n, the new line character? Variable names in PHP must start with a dollar sign and follow by a letter or an underscore. Variable names in PHP must start with a dollar sign and follow by a letter or an underscore.

5 PHP- Arrays Array names have the same format and restriction as variable names Array names have the same format and restriction as variable names Use keyword: array to construct an array Use keyword: array to construct an array –$courses = array(‘perl’, ‘php’, ‘Java’, ‘Javascript’); –print $courses[1]; Associative arrays (Hashes in Perl) are defined in a similar fashion. Associative arrays (Hashes in Perl) are defined in a similar fashion. –$kids_age = array (‘John’=> 4, ‘Mary’=>6); –print $kids_age[‘John’];

6 PHP- output Any output from a PHP script becomes part of the HTML document the PHP processor is building. Any output from a PHP script becomes part of the HTML document the PHP processor is building. print print –Print “Welcome to my home page ”; echo echo –echo “Apples are red ”, “Bananas are yellow ”; printf (Similar to the printf in C language) printf (Similar to the printf in C language)

7 PHP – Control Statements Relational operators & Boolean operators Relational operators & Boolean operators >, >=, ==, !=, ===, and, &&, or, ||. if - elseif – else if - elseif – else if ( $first== $second) {statement(s);} elseif( $first== $third) {statement(s);} else {statement(s);} for for for ( $count=1; $count <=; $count++ ) {loop statement(s);} {loop statement(s);} while, do-while, switch are similar to JavaScript. while, do-while, switch are similar to JavaScript.

8 Exercise 12-1 First PHP program Prepare the folder for storing PHP programs Prepare the folder for storing PHP programs –Create a folder: public_php paralleled to your public_html folder in your AFS (S:) Drive Assign “read” permission to your public_php folder Assign “read” permission to your public_php folder –Telnet to you afs account Start, Run, Open: telnet –At the Microsoft Telnet prompt type o gpunix.umr.edu –Login with your id and password. Hit enter twice until you reach the gpunix prompt –Type the following command at the prompt fs setacl public_php system:anyuser read –Logout and close the telnet program

9 Exercise 12-1 First PHP program Create your first PHP program Create your first PHP program –Open up Notepad ( You may use Dreamweaver to create a new php dynamic page) –Type in the following php code. (In Dreamweaver, eliminate all the initial tags first) <?php # This program prints out a simple message print ("My first PHP program "); ?> Save this file as ex12_1.php under S: public_php/ Save this file as ex12_1.php under S: public_php/ –if you are using notepad, make sure to select All files from the “Save as type” dropdown list Open up a browser and type the following URL to access the file Open up a browser and type the following URL to access the filehttp://acmphp.cs.umr.edu/~<your_username>/ex12-1.php –Be sure to replace with your id

10 Exercise 12-2 Second PHP program Create your second PHP program Create your second PHP program –Type in the following php code. <html><head> Generating HTML From PHP Generating HTML From PHP </head><body> Generating HTML from PHP Generating HTML from PHP <?php print ("Using PHP has some advantages: "); print ("Using PHP has some advantages: "); print (" Speed Ease of use print (" Speed Ease of use Functionality "); Functionality "); print (" "); print (" ");

11 Exercise 12-2 Second PHP program Note that this code may look like an html but it is actually an html embedded php. Note that this code may look like an html but it is actually an html embedded php. Save this file as ex12_2.php under S: public_php/ Save this file as ex12_2.php under S: public_php/ Open up a browser and view this php file from Open up a browser and view this php file from http://acmphp.cs.umr.edu/~<your_username >/ex12-2.php http://acmphp.cs.umr.edu/~<your_username >/ex12-2.php Add two hyper links for exercises ex 12_1 and ex 12_2. Label the link as First and second PHP exercises


Download ppt "IST 221 Internet Concepts and Applications Introduction to PHP."

Similar presentations


Ads by Google