Sie sind auf Seite 1von 5

[ ] see outsourced tv series

v01-v02 Notes www.php.net - official website PHP 5 - current 'major' version download from: http://www.apachefriends.org/en/xampp.html http://www.wampserver.com/en v18-v19 Notes <? if ($num==1) { // do something } else if ($num==2) { // do something } else { // do something } ?> v20 Notes <? $num = 10; $num += 1; $num -= 1; $num *= 1; $num /= 1; $num %= 1; $str .= 'more text'; ?> v21: Comparison Operators <?php // == is // != is // > is // >= is // < is // <= is if ($number1 echo } else { echo } ?> v22: Arithmetic Operators <?php // ( ) // + // // * // / // %

// 1 = TRUE

EQUAL TO NOT EQUAL TO GREATER THAN GREATER THAN LESS THAN LESS THAN OR == $number2) "true."; "false.";

(<>) OR EQUAL TO EQUAL TO {

is used for PRECEDENCE is ADDITION is SUBTRACTION is MULTIPLICATION is DIVISION is MODULUS (GET REMAINDER OF DIVISION)

// // // ?>

++ -PEMDAS

is INCREMENT is DECREMENT is still the operator precedence

v23: Logical Operators <?php // && ND') // ') // !

is the AND Operator (you can also use 'A is the OR Operator (you can also use 'OR is the NOT Operator

if ( $number>=$lower && $number<=$higher ) { // do something } ?> v24: Triple Equals <?php // === means comparison CONSIDERING DATA TYPE if ( $letters === $numbers ) { // will not be true } ?> v25: While Loops <?php $counter = 1; while ( $counter <= 10 ) { echo $counter; $counter++; } ?> v26: Do While Loops <?php // DO WHILE always EXECUTE ONCE. do { echo 'This will ALWAYS show.'; } while ( false ) // even if this is false ?> v27: For Loop <?php for ($counter = 1; $counter <= 10; $counter++) { echo $counter . '<BR>'; } ?> v28: Switch Statements <?php $num = 1; switch ($num) { case 1: echo 'One'; // fall through case 2:

echo 'Two'; break; case 'string is ok': echo 'Wow String'; break; default: echo 'should none be true'; break; } ?> v29: DIE and EXIT Functions <?php @mysql_connect('localhost','root','') OR die('ERROR MESSAGE YOU WANT'); // mysql_connect() command connects to database. // preceeding with an '@' suppresses error message. // OR will no longer process die, if mysql_connect returns true. exit('IS JUST THE SAME AS DIE'); ?> v30: Basic Functions <?php function customFunction() { echo 'this is from a custom function.<BR>'; } customFunction() ?> v31: Function with Arguements <?php // function structures your code better. function addThese($a, $b) { return $a + $b; } addThese(1,2); // some more concepts: // 'missing arguement' error // ?> v32: Function with Return Values <?php // notice the return line in v31 ?> v33: Global Variables and Functions <?php $user_ip = $_SERVER['REMOTE_ADDR']; function echo_ip() { global $user_ip; // to import a global variable } ?> v34-36: String Functions PART 1-3 <?php $string = 'this is an example string'; // str_word_count($string, 0) RETURNS WORD COUNT

echo 'word count: ' . str_word_count($string, 0) . '<BR>'; // str_word_count($string, 1) RETURNS AN ARRAY $swc = str_word_count($string, 1); print_r($swc); // third parameters specifies chars that will be considered wopr ds. $swc = str_word_count($string, 1, '&.!'); print_r($swc); // shuffles the characters in the string. echo str_shuffle($string); // get string length echo strlen($string); // returns a substring echo substr($string, 0, 10); // returns a reversed string echo strrev($string); // compares strings $string_one = 'version 1'; $string_two = 'version 2'; similar_text($string_one, $string_two, $result); echo 'the similarity between is ' . $result; ?> v37: Strings PART 4 <?php $trimmed = trim(' enclosed in space '); // trims the white spaces from the left and right of the string // ltrim() and rtrim() is also available addslashes(); // - Returns a string with backslashes before char acters that need to be quoted in database queries etc. These characters are sing le quote ('), double quote ("), backslash (\) and NUL (the NULL byte). stripslashes(); // - Un-quotes a quoted string htmlentities(); // - This function is useful in preventing usersupplied text from containing HTML markup, such as in a message board or guest b ook application. ?> v38: Arrays Intro <?php // use the array keyword $food = array('pasta','pizza','salad'); // arrays are zero based. echo $food[1]; // to access pizza // prints an array

print_r($food); // to add $food[4] = 'Fruit'; ?> v39: Associative Arrays <?php // associative array's keys are literals! instead of numbers. $food = array('pizza'=>300,'pasta'=>1000,'salad'=>150,'vegetable s'=>50); echo $food['pizza']; // will output 300 ?> v40: Multi Dimensional Arrays <?php $food = array('Healthy'=> array('Salad','Vegetables') ,'Unhealthy'=> array('Pizza','i ce cream')); echo $food['Healthy'][0]; ?> EXTRAS: <?php echo 'this is the recommended way to print var ' . $var; // . is the CONCATENATION OPERATOR // bool >0:TRUE; <=0:FALSE // \ is an ESCAPE CHARACTER. ?>

Das könnte Ihnen auch gefallen