1 / 11

IST 221 Internet Concepts and Applications

IST 221 Internet Concepts and Applications. Introduction to PHP. PHP, Hypertext Preprocessor. A Server side HTML embedded scripting Language. An Alternative to perl-CGI, ASP, JSP and Cold Fusion. PHP is similar to Javascript, but on the server side. PHP Syntax.

Download Presentation

IST 221 Internet Concepts and Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IST 221 Internet Concepts and Applications Introduction to PHP

  2. PHP, Hypertext Preprocessor • A Server side HTML embedded scripting Language. • An Alternative to perl-CGI, ASP, JSP and Cold Fusion. • 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 • PHP uses dynamic typing. • PHP variable names are case sensitive • PHP tag: <?php …… ?> • Comments: # , // and /*…..*/

  4. PHP Primitives • Variables: Integer, Double, String and Boolean. • 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.

  5. PHP- Arrays • Array names have the same format and restriction as variable names • 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. • $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. • print • Print “Welcome to my home page<br/>”; • echo • echo “Apples are red <br/>”, “Bananas are yellow <br/>”; • printf (Similar to the printf in C language)

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

  8. Exercise 12-1 First PHP program • 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 • 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 • 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/ • 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 http://acmphp.cs.umr.edu/~<your_username>/ex12-1.php • Be sure to replace <your_username> with your id

  10. Exercise 12-2 Second PHP program • Create your second PHP program • Type in the following php code. <html> <head> <title> Generating HTML From PHP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <h1>Generating HTML from PHP</h1> <?php print ("Using PHP has <i>some advantages:</i>"); print ("<ul><li>Speed</li><li>Ease of use</li> <li>Functionality</li></ul>"); print ("</body></html>");

  11. Exercise 12-2 Second PHP program • 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/ • Open up a browser and view this php file from 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

More Related