Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP PART 2.

Similar presentations


Presentation on theme: "PHP PART 2."— Presentation transcript:

1 PHP PART 2

2 23.2 PHP Basics (Cont.) Array names, like other variables, begin with the $ symbol. Function count returns the total number of elements in the array. Function array creates an array that contains the arguments passed to it.

3 23.2 PHP Basics (Cont.) Arrays with nonnumeric indices are called associative arrays. You can create an associative array using the operator => Function reset sets the internal pointer to the first array element. Function key returns the index of the element currently referenced by the internal pointer, function next moves the internal pointer to the next element. The foreach statement, designed for iterating through arrays,

4 Outline (1 of 4) Automatically creates array $first
arrays.php (1 of 4) Automatically creates array $first Sets the first element of array $first to the string “zero” “three” is appended to the end of array $first Returns the number of elements in the array

5 Outline arrays.php (2 of 4) Function array creates array $second with its arguments as elements Creates associative array $third Sets the internal pointer to the first array element in $third Returns the index of the element being pointed to Moves the internal pointer to the next element and returns it

6 Outline arrays.php (3 of 4) Uses operator => to initialize the element with index “January” to have value “first” Iterates through each element in array $fourth Stores the index of the element Stores the value of the element

7 Outline arrays.php (4 of 4)

8 23.3 String Processing and Regular Expressions
Function strcmp compares two strings. The function returns -1 if the first string alphabetically precedes the second string, 0 if the strings are equal, and 1 if the first string alphabetically follows the second.

9 Outline compare.php (1 of 2) Checks whether the ith element of the fruits array preceeds the string banana

10 Outline compare.php (2 of 2) Uses relational operators to compare the element of the fruits array with the string apple

11 23.3 String Processing and Regular Expressions (Cont.)
Function ereg receives a regular expression pattern to search for and the string to search. Function eregi performs case-insensitive pattern matches. Regular expressions can include metacharacters that specify patterns. caret (^) metacharacter matches the beginning of a string, dollar sign ($) matches the end of a string. period (.) metacharacter matches any single character.

12 23.4 Form Processing and Business Logic
The arrays $_GET and $_POST retrieve information sent to the server by HTTP get and post requests, respectively. Using method = "post" appends form data to the browser request that contains the protocol and the requested resource’s URL. Scripts located on the web server’s machine can access the form data sent as part of the request.

13 Fig. 23.11 | Some useful superglobal arrays.
Global arrays are associative arrays predefined by PHP that hold environment or the web server and are accessible in any scope. DETAILED INFORMATION Fig | Some useful superglobal arrays.

14 Outline form.html (1 of 4) Appends form data to the browser request that contains the protocol and the URL of the requested resource Form data is posted to form.php to be processed

15 Outline (2 of 4) Creates form fields
form.html (2 of 4) Creates form fields Creates drop-down list with book names

16 Outline form.html (3 of 4) Creates radio buttons with “Windows XP” initially selected

17 Outline form.html (4 of 4)

18 Good Programming Practice 23.1
Use meaningful XHTML object names for input fields. This makes PHP scripts that retrieve form data easier to understand.

19 23.4 Form Processing and Business Logic (Cont.)
Function extract creates a variable/value pair corresponding to each key/value pair in the associative array passed as an argument. Business logic, or business rules, ensures that only valid information is stored in databases. Function die terminates script execution.

20 Outline form.php (1 of 5)

21 Creates a variable/value pair for each key/value pair in $_POST
Outline form.php (2 of 5) Ensures that phone number is in proper format Terminates execution and closes the document properly

22 Outline form.php (3 of 5) Prints the value entered in the field in form.html

23 Outline form.php (4 of 5)

24 Outline form.php (5 of 5)


Download ppt "PHP PART 2."

Similar presentations


Ads by Google