1 / 19

JavaScript

JavaScript. Document Node / Intro to Php. Document Tree. Check Document Tree. Dynamically Add node, Remove node. p arentNode -- Returns the parent node of an element childNodes [] ---Returns an array of child nodes for an element Create Node ---- createElement ( NameofTag )

belle
Download Presentation

JavaScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaScript Document Node / Intro to Php

  2. Document Tree

  3. Check Document Tree

  4. Dynamically Add node, Remove node • parentNode-- Returns the parent node of an element • childNodes[] ---Returns an array of child nodes for an element • Create Node ---- createElement(NameofTag) • Add Node --- appendChild(element) • Remove Node --- removeChild(element) • Insert Node --- insertBefore(newelement, oldelement) • Replace Child Node --- replaceChild(newelement, oldelement)

  5. Example • Create an paragraph element • varnewnode = document.createElement(“p”); • Create new items and add it to the list. varmyElement = document.createElement("li"); myElement.innerHTML = "HI, hi"; varcontentlist =document.getElementById("displayContents"); contentlist.appendChild(myElement);

  6. Php • Server Side Web Programming • A script file embedded directly into HTML documents • * unlike javascript, php is server side application • Php code is processed by server --- Client can not see the actual phpcodes • Php must be supported by the web server • Any file with php code block should be named with extension . php

  7. The first php program • PHP script has start and end tags, most commonly used are <?php print(“welcome to php”); ?> • <?php ?> can be placed anywhere in HTML markup. • Each command line ends with ; • Comment : // , #, /* */ • Variable starts with a $ sign. • ** php is mostly case insensitive.

  8. First PHP program • Client Side <html> <head> <title>php file</title> </head> <body> welcome to php </body> </html> • Sever side <html> <head> <title>php file</title> </head> <body> <?php print("welcome to php"); ?> </body> </html>

  9. First PHP program pratice • Make sure XAMPP is running on your computer • Copy first.php file to xampp/htdocs/xampp/external • Change “$name = "Paul";” to your name • Open Firefox/chrome • Type in addressbar: localhost/xampp/external/first.php • View the page source

  10. Php type • Php variables are loosely typed – can contain different types of data • Data Type • Four scalar type: integer/int, float/double/real, boolean, string • Two compound type: array, object • Special type: • Resource: hold a reference to external resource (information from database) • NULL: the varible has no value. (either not set or unset()). • **The type of variable is usually decided by php at runtime, not programmer.

  11. Data Type example : gettype() and settype() <?php $testfloat = 1.2; $testint = 2; $testint1 = 1; $teststring = "This is string"; $testbool = FALSE; ?> testbool is of type <?php print(gettype($testbool)); ?> <br \> testint is of type <?php print(gettype($testint)); ?> <br \> Convertestint to double <?phpsettype($testint,"double"); ?> , now testint is of type <?php print(gettype($testint)); ?> <br \>

  12. Output foo is 0 foo is 2 foo is 2.2 foo is 15 foo is 15.2 Type casting and automatical type conversion. <?php $foo = "0"; // $foo is string (ASCII 48) print("foo is $foo <br>"); $foo += 2; // $foo is now an integer (2) print("foo is $foo <br>"); $foo =(float) $foo +0.2; // $foo is now a float (3.3) print("foo is $foo <br>"); $foo = 5 + "10 Little Piggies"; print("foo is $foo <br>"); $foo = 5 + "10.2 Small Pigs"; print("foo is $foo <br>"); ?>

  13. <?php $a = 1; $a = $a + 4; print("After addition: $a <br\>"); $a = $a - 4; print("After substraction: $a <br\>"); $a *=2; print("After multiplication: $a<br\>"); $a +="5 dollars"; print("add by a string:$a <br\>"); $a =$a/2; print("after division:$a <br\>"); ?> Arithmetic Operators • Addtion + • Subtraction – • Multiplication * • Division / • Shortcut • $a = $a+1; • $a += 1;

  14. Php keyword

  15. Array • Array is a collection of data, with the first index be zero. • You can use array() to construct an array $HotelReservation = array(“Dona May”, 2, 89.95, true); • You can initialize one by one $HotelReservation[] = “Dona May”; $HotelReservation[] = 2; $HotelReservation[2]=89.95;

  16. Print Array • For structure • count($Array) will return the number of elements in Array for ( $i = 0; $i < count( $first ); $i++ ) print(“Element $ i is $first[$i]”); • For each structure foreach($first as $value) { print("<p> $value </p>"); }

  17. Associative Array • The index is not numeric values $third[ "Amy" ] = 21; $third[ "Bob" ] = 18; $third[ "Carol" ] = 23; • Or you can use array function $third = array( "Amy" => 21, "Bob" => 18 , "Carol" => 23 );

  18. Iterate through Associative Array • foreach foreach ($third as $key => $value) { print( "<p>$key is $third[$key]</p>" ); } • foreach – control statement that is specially designed for iterating through arrays • foreach ( $third as $element => $value ) • $third is the array • as is the keyword • $element will store the index of each element • $value will store the value of each element

  19. Global Array • $GLOBALS • Contains a reference to every variable which is currently available within the global scope of the script. • $_SERVER • Variables set by the web server or otherwise directly related to the execution environment of the current script. • $_GET • Variables provided to the script via URL query string. • $_POST • Variables provided to the script via HTTP POST. • $_ENV • Variables provided to the script via the environment. • $_COOKIE • Variables provided to the script via HTTP cookies. • * Check file env.php • Change the file to output the IP address of the remote computer. • http://www.php.net/manual/en/reserved.variables.php

More Related