Monday, 21 November 2011

php lecture 8


this is lecture8 NT322 Lecture #9 # Wednesday November 8 / Friday November 11, 2011 # Basic PHP Language Syntax: // while loop: 12345678910
0123456789
12345678910
Current value of $v: 1
Current value of $v: 2
Current value of $v: 3
Current value of $v: 17

$a[0] is 2.3
0$a[1] is 98
1$a[2] is Hello World
2$a[3] is Seneca College
3$a[4] is 3.14
4$a[5] is 451
5
after math operations... $a[0] is 6.67
after math operations... $a[1] is 1862
after math operations... $a[2] is 0
after math operations... $a[3] is 0
after math operations... $a[4] is 9.8596
after math operations... $a[5] is 203401

i equals 2
$i is: 2
SERVER_NAME is: zenit.senecac.on.ca
PHP_SELF is: /lecture.php
REMOTE_ADDR is: 70.25.225.30
i is: 99
in the function $x is: YYY
outside of the function...$x is: ABC
Monday November 21 2011 EST10:39:22 PMportion is: 'sea shells by the seashore' string1 is: 'she sells sea shells by the seashore' strrev and strtoupper: 'EROHSAES EHT YB SLLEHS AES SLLES EHS'




test



this is lecture8


NT322 Lecture #9
# Wednesday November 8 / Friday November 11, 2011
# Basic PHP Language Syntax:

// while loop:
\n";

// do/while loop:
$i = 0;
do {
print $i++;
} while ($i< 10); echo "
\n";

// for loop:
for($i = 1; $i <= 10; $i++) { print $i; } echo "
\n";

// foreach loops:
$a = array(1, 2, 3, 17); // declaring arrays

foreach($a as $v) {
print "Current value of \$v: $v
";
}
echo "
\n";

/* values and keys */
$a = array(2.3, 98, "Hello World", "Seneca College", 3.14, 451);
$b = array(2.9, 19, "Hello World", "Seneca College", 3.14, 451);

foreach($a as $k => $v) {
print "\$a[$k] is $v
\n";

}
echo "
\n";

foreach($a as $k => $v) {
$a[$k] *= $b[$k];
print "after math operations... \$a[$k] is $a[$k]
\n";
}
echo "
\n";

$i = 2;

// switch/case:
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
default:
print "i is not equal to 0, 1 or 2";
}
echo "
\n";

// control structures:
if($i == 0) {
print "\$i is: $i
\n";
}
else if($i == 1) {
print "\$i is: $i
\n";
}
else if($i == 2) {
print "\$i is: $i
\n";
}
else if($i == 3) {
print "\$i is: $i
\n";
}
else {
print "\$i is > 3: $i
\n";
}

// predefined variables:

$x = $_SERVER['SERVER_NAME'];
print "SERVER_NAME is: $x
\n";
// the name of the server host

$x = $_SERVER['REQUEST_METHOD'];
// 'GET', 'HEAD', 'POST' or 'PUT'

$x = $_SERVER['PHP_SELF'];
print "PHP_SELF is: $x
\n";
// the filename of the currently executing script

$x = $_SERVER['REMOTE_ADDR'];
print "REMOTE_ADDR is: $x
\n";
// the IP address from which the user is viewing the current page.

$i = 99;
?>

\n";

function display($myparam){
$x = $myparam;
print "in the function \$x is: $x
\n";
}
display("YYY");
print "outside of the function...\$x is: $x
\n";
// will output: "ABC"

// DATE functions:

echo date("l F d Y T");

// date( ) built-in PHP function.
// l = day_of_week name
// F = month name
// d = 2-digit day of month
// Y = 4 digit year
// T = timezone

echo date("h:i:s A");

// h = 2-digit hours
// i = 2-digit minutes
// s = 2-digit seconds
// A = AM/PM

// common variable functions
/*
empty - Determine whether a variable is set
isset - same as !empty($a)
gettype - Get the type of a variable
get_defined_vars - Returns an array of all defined variables
is_array - Finds whether a variable is an array
is_bool - Finds out whether a variable is a boolean
is_float - Finds whether a variable is a float
is_int - Find whether a variable is an integer
is_null - Finds whether a variable is NULL
is_numeric - Finds whether a variable is a number or a numeric string
is_object - Finds whether a variable is an object
is_string - Finds whether a variable is a string
unset - Unset a given variable
functions for debugging :
print_r - Prints human-readable information about a variable
var_dump - Dumps information about a variable
*/

// common string functions:
/*
chop - Strip whitespace from the end of a string
chr - Return a specific character
crypt - DES-encrypt a string
htmlspecialchars - Convert special characters to HTML entities
md5 - Calculate the md5 hash of a string
nl2br - Inserts HTML line breaks before all newlines in a string
ord - Return ASCII value of character
sprintf - Return a formatted string
strip_tags - Strip HTML and PHP tags from a string
addslashes - Quote string with slashes
stripslashes - Un-quote string quoted with addslashes()
strlen - Get string length
strpos - Find position of first occurrence of a string
strrev - Reverse a string
strtolower - Make a string lowercase
strtoupper - Make a string uppercase
str_replace - Replace all occurrences of the search string with the replacement string
join - Join array elements with a string
split - split string into array by regular expression
*/

$string1 = "she sells sea shells by the seashore";
$portion = substr($string1, 10);
echo "portion is: '$portion'
\n";
echo "string1 is: '$string1'
\n";
echo "strrev and strtoupper: '" . strrev(strtoupper($string1)) . "'
\n";

// common array functions:
/*
count - Count elements in an array/object
array_pop - Pop the element off the end of array
array_push - Push one or more elements onto the end of array
array_reverse - Return an array with elements in reverse order
array_shift - Shift an element off the beginning of array
array_unshift - Prepend one or more elements to the beginning of array
array_sum - Calculate the sum of values in an array.
array_unique - Removes duplicate values from an array
array_values - Return all the values of an array
in_array - Return TRUE if a value exists in an array
array_search - Searches the array for a given value and returns the corresponding key if successful
sizeof - Get the number of elements in an array/object
sort - Sort an array
uksort - Sort an array by keys using a user-defined comparison function
usort - Sort an array by values using a user-defined comparison function
*/
?>



No comments:

Post a Comment