Title: COSC 416 week seven
1COSC 416week seven http//iat.ubalt.edu/courses/
cosc416.101_sp08/
2Programming
3Math
4Math
5Variables
6Variables
7Variables
- a_number 2 another_number
8Variables
- parameter 2 return_value
- 2 2 ?
9Variables
- parameter 2 return_value
- 2 2 4
10Math
11Math
12Functions
- f(parameter) return_value
13Functions
- f(x, y) x y
- f(10, 10) ?
- f(1, 100) ?
14Functions
- f(x, y) x y
- f(10, 10) 20
- f(1, 100) 101
15Functions
- f(x, y) x y
- f(10, f(10, 10)) ?
16Functions
- f(x, y) x y
- f(10, f(10, 10)) 30
17Functions
- f(x, y) x y
- f(10, f(10, 10)) 30
- f(10, 20) 30
18Functions
- f(x, y) x y
- z f(10, 10)
- f(10, z) 30
19Functions
20Functions
- sum(x, y) x y
- add_two_to(x) x 2
- sum(10, 20) ?
- add_two_to(6) ?
21Functions
- sum(x, y) x y
- add_two_to(x) x 2
- sum(10, 20) 30
- add_two_to(6) 8
22Functions
- sum(x, y) x y
- add_two_to(x) x 2
- z sum(10, 10)
- add_two_to(z) 22
23Functions
- sum(x, y) x y
- add_two_to(x)
- sum(x, 2)
24PHP Functions
- function sum(x, y)
- return x y
-
- function add_two_to(x)
- return sum(x, 2)
-
- z 20
- add_two_to(z)
25PHP Functions
- function name(parameters)
- // manipulate parameters
- return return_value
26PHP Functions
- function k(parameter)
- return parameter
-
- initial 2
- new_value k(initial)
27PHP
28Webclient
www.example.comWeb server
HTTP server
HTTP client
80
index.html
29Webclient
www.example.comWeb server
HTTP server
HTTP client
80
index.html
PHPinterpreter
30Webclient
www.example.comWeb server
Should PHP be used to process this request?
HTTP server
HTTP client
80
index.html
PHPinterpreter
31Webclient
www.example.comWeb server
No
GET /index.html
HTTP server
HTTP client
80
index.html
PHPinterpreter
32Webclient
www.example.comWeb server
Yes
GET /index.php
HTTP server
HTTP client
80
index.php
PHPinterpreter
33Client
Server
HTTP server
PHP
Should therequested filebe processedby PHP?
HTTP request
34Client
Server
HTTP server
PHP
Should therequested filebe processedby PHP?
HTTP request
No
Add HTML from the file to an HTTPresponse
HTTP response
35.php file extension turns on the PHP
interpreter(on our server)
36Client
Server
HTTP server
PHP
Should thefile requestedbe processedby PHP?
HTTP request
Execute any PHP code in the file
Yes
Send interpreted file to HTTP server
Add PHP output as HTML to an HTTPresponse
HTTP response
37.php file extension turns on the PHP
interpreter(on our server)
38HTTP server
PHP
hello.php
...ltpgtlt?php echo "hello"?gtlt/pgt...
GET hello.php
...ltpgthellolt/pgt...
HTTP response
39PHP code
Open and close tags
lt?php?gt
40PHP code
Statements
lt?php echo "Hi"?gt
41PHP code
Semicolons!
lt?php echo "Hi"?gt
42PHP code
Comments
lt?php outputs Hi echo "Hi"?gt
43PHP code
Types Numbers
lt?php integer 1 float 1.1?gt
44PHP code
Types Strings
lt?php string "Hi" string 'Hi'?gt
45PHP code
Escaping in strings
lt?php msg "Say \"Hi\""?gt
46PHP code
Combining strings
lt?php s "Hi"." there" s "Hi there"?gt
47PHP code
Types Arrays
lt?php array array() array 'Hi'
array0 Hi?gt
48(No Transcript)
49The white screen of death
Check your semicolonslt?php echo "Hello"?gt
50The white screen of death
Check your semicolonslt?php echo "Hello"?gt
51The white screen of death
Check your quoteslt?php echo "Hello?gt
52The white screen of death
Check your quoteslt?php echo "Hello"?gt
53The white screen of death
Check your parentheseslt?php echo("Hello"?gt
54The white screen of death
Check your parentheseslt?php echo("Hello")?gt
55The white screen of death
Check your curly braceslt?php if (a b)
echo "True!"?gt
56The white screen of death
Check your curly braceslt?php if (a b)
echo "True!" ?gt