Mdst 3559-02-15-php


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Mdst 3559-02-15-php

  1. 1. PHP<br />MDST 3559: DataestheticsProf. Alvarado02/15/2011<br />
  2. 2. Business<br />VPN?<br />Assignment grades will be posted in Collab<br />
  3. 3. Review<br />JavaScript is a client-side language<br />Controls behavior of the document<br />Works on the document as a data structure<br />jQuery is a JavaScript library<br />Makes working with JavaScript easier<br />Uses CSS selectors to access and manipulate document elements<br />
  4. 4. jQuery Libraries<br />jQuery<br />Core library, provides selectors and basic effects<br /><br />jQuery UI<br />Provides user Interface functions, e.g. Tabs<br /> (See Demos)<br />jQueryplugins<br />Hundreds of functions and effects<br /><br />
  5. 5. Another jQuery Example<br />Create a class for notes that can be turned on an off<br />Show jQuery features:<br />Manipulation: new text added<br />Traversing: moving between elements<br />Dynamic CSS: add styles dynamically to elements<br />
  6. 6. Overview<br />Today we shift to PHP – a server-side programming language<br />
  7. 7. Client vs. Server Side <br />All programs are human written sequences of commands that control the computer<br />Programs are first “compiled” into a machine language<br />When a program is “executed,” it produces an effect<br />
  8. 8. Client vs. Server Side <br />In web programming, web pages can have either server-side or client-side programs embedded in them<br />Server-side code gets executed before the page is delivered to the browser<br />Client-side code gets executed after the page is delivered to the browser<br />
  9. 9.
  10. 10. PHP<br />PHP is a simple server-side programming language<br />It was invented in 1994 by RasmusLerdorf, a Danish Canadian, as a way to simplify the process of writing server-side programs<br />These older programs were called “CGI scripts” <br />Originally PHP stood for “Personal Home Page,” now it just means PHP ...<br />
  11. 11.
  12. 12. Exercise 1: Hello, World!<br />Create a new file, hello.php<br />Create an H1 Element called “Introduction to PHP”<br />Create an H2 Element called “Exercise 1”<br />Enter the following code:<br /><p><br /><?php<br />echo “Hello, World!”;<br />?><br /></p><br />
  13. 13. Observations<br />PHP files must end in .php<br />Otherwise, not executed, treated as text<br />PHP code must live inside of the opening and closing “tags” <?php and ?><br />This looks like XML but it is not<br />Anything outside of these tags is regular content, e.g. plain text, HTML, or XML<br />echo is just a function that prints its argument to the screen <br />echo does note require parantheses<br />Your browser knows nothing about the PHP<br />
  14. 14. Exercise 2: Variables<br />Comment out your first echo statement<br />Define a variable to hold the string “Hello, World!”<br />Use echo to print the variable to the screen<br />
  15. 15. Variables<br />Always prefixed by $<br />Variables hold values<br />VariableS are assigned values with the = sign<br />Variables are always on the left<br />
  16. 16. Exercise 3: Variable Types<br />Comment out your last echo statement<br />Create a new variable called $notd (for “number of the day”) and give it a numeric value, e.g.<br />$notd = (42 * 5) + 29;<br />Do not use quotes<br />Append text to your message variable<br />$message .= “The message of the day is: ”;<br />Then echo the message and the notd together<br />echo “$message $notd”;<br />
  17. 17. Observations<br />Values can be strings, numbers, or other things<br />Strings are always quoted (in single or double quotes)<br />Numbers are never quoted<br />Number can be the result of an equations<br />Operators: + - * / (also: ^ and %)<br />
  18. 18. Exercise 4: Arrays<br />Create a new file rex.php<br />Invoke the file() function to grab a file from the web and assign the return value to the variable $contents<br />Use the URL from post [8.1] on the blog<br />$url = '.’;<br />$contents = get($url);<br />Invoke echo to print out $contents to screen<br />
  19. 19. Observation <br />What do we see?<br />PHP is telling us that $contents is an array, not a string<br />What is an array?<br />
  20. 20. Arrays<br />Arrays are built-in data structures in the PHP language<br />A data type that holds other data types (strings, numbers, other arrays)<br />Each stores a list of values<br />The items in the list are indexed a number starting with 0<br />Let’s look back at our example ...<br />
  21. 21. Exercise 5<br />Iterate through the $contents array using the foreach() function<br />Then iterate through the $contents array using the for() function<br />
  22. 22. Observations<br />Arrays have a length, or size<br />The size is always 1 greater than the last index value<br />Since the index begins with “0”<br />Iterating through arrays allows you to modify each item in the array<br />Text files are often represented as arrays<br />
  23. 23. Exercise 6<br />Using the foreach() function, format each line<br />Skip the first 5 lines<br />Remove the trailing new line<br />wrap each $line in paragraph tags<br />