php and javascript nov. 26, 2013 kyung eun park computer and creativity (cosc109) towson university
TRANSCRIPT
![Page 1: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/1.jpg)
PHP and JavaScript
Nov. 26, 2013Kyung Eun Park
Computer and Creativity (COSC109)
Towson University
![Page 2: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/2.jpg)
2
Table of Contents1. PHP
2. JavaScript
3. XAMPP
![Page 3: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/3.jpg)
3
PHPThe language that you use to make the server
generate dynamic output.
PHP documents end with the extension .php.
A Web server passes a PHP program to the PHP processor.
A new tag to trigger the PHP commands:<?php … ?>
<?php
echo “Hello World”;
?>
![Page 4: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/4.jpg)
4
The Structure of PHPLooks more like Java, but flexible language
Semicolons: PHP commands ends with a semicolon
$ symbol: placed in front of all variables<?php
$mycounter = 1;
$mystring = “Hello”;
$myarray = array(“One”, “Two”, “Three”);
?>
![Page 5: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/5.jpg)
5
PHP Variables (1)String variables
<?php
$username = “Tom Sawyer”;
echo $username;
?>
Numeric variables<?php
$count = 17;
echo $count;
?>
![Page 6: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/6.jpg)
6
PHP Variables (2)Array variables
<?php
$team= array(“Bill”, “Joe”, “Mike”, “Chris”, “Jim”);
echo $team[3];
?>
![Page 7: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/7.jpg)
7
PHP OperatorsArithmetic operators: +, -, *, /, %, ++, --
Assignment operators: =, +=, -=, *=, /=, .=, %=
Comparison operators: ==, !=, >, <, >=, <=
Logical operators: &&, and, ||, or, !, xor
![Page 8: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/8.jpg)
8
PHP Variable operationsAssignment
$x = 10;
$+=10;
$y =20;
$y -=10;
Variable incrementing and decrementing++$x;
--$y;
![Page 9: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/9.jpg)
9
PHP StringString concatenation
echo “You have ”.$msgs.“ messages.”;
$bulletin .= $newsflash;
Variable substitution echo “There have been $count presidents of the US.”;
Escaping characters$text = “My mother always said \”Eat your greens\”.”;
![Page 10: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/10.jpg)
10
Multiline String VariableMultiple lines between quotes
<<< operator<?php
$author = “Alfred E Newman”;
$out = <<<_END
This is a Headline
This is the first line.
This is the second.
- Written by $author.
_End;
?>
![Page 11: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/11.jpg)
11
PHP Variable TypingPHP is a very loosely typed language.
No need to declare variables before they are used. Context-based variable typing by PHP if necessary.
<?php
$number = 12345 * 67890;
echo substr($number, 3, 1);
?>
<?php
$pi = “3.1415927”;
$radius = 5;
echo $pi * ($radius * $radius);
?>
![Page 12: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/12.jpg)
12
PHP ConstantsSimilar to variables, but its value is set for the
remainder of the program and cannot be altered.
define(“ROOT_LOCATION”, “/usr/local/www/”);
$directory = ROOT_LOCATION;
Predefined constants__LINE__, __FILE__, __DIR__, __FUNCTION__,
__CLASS__, __METHOD__, __NAMESPACE__
![Page 13: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/13.jpg)
13
PHP FunctionTo separate out sections of code that perform a
particular task.<?php
$temp = “The date is “;
echo $temp.longdate(time());
function longdate($timestamp) {return date(“ 1 F jS Y”, $timestamp);
}
?>
![Page 14: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/14.jpg)
14
JavaScriptClient-side scripting language that runs entirely inside the
web browser
Placed between opening <script> and closing </script> HTML tags
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<script>
document.write(“<p>My First JavaScript</p>”);
</script>
</body>
</html>
![Page 15: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/15.jpg)
15
JavaScript Function<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
alert("Hello World!");
}
</script>
</head>
<body>
<button onclick="myFunction()">Try it</button>
</body>
</html>
![Page 16: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/16.jpg)
16
JavaScript VariablesString variables
greeting = “hello there”
newstring = greeting
document.writing(newstring)
Numeric Variablescount = 42
temperature = 100.0
Arraystoys = [“bat”, “ball”, “whistle”, “puzzle”, “doll”]
document.write(toys[3]);
![Page 17: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/17.jpg)
17
JavaScript OperatorsArithmetic operators: +, -, *, /, %, ++, --
Assignment operators: =, +=(string too), -=, *=, /=, %=
Comparison operators: ==, !=, >, <, >=, <=, ===, !==
Logical operators: &&, ||, !
Incrementing and Decrementing operators: ++, --
String concatenation: +
Escaping Characters: \b, \n, \t, \’, \”, \\, etc.
![Page 18: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/18.jpg)
18
JavaScript TypingLike PHP, JavaScript is a very loosely typed
languageDetermined only when a value is assigned and can
change as the variable appears in different contexts
![Page 19: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/19.jpg)
19
Installing XAMPP Free and open source cross-platform Web server solution stack pagkage
consisting of: The Apache HTTP Server MySQL database Interpreters for scripts written in the PHP and Perl programming language X(cross-platform), Apache HTTP Server, MySQL, PHP, Perl
Intended it for use only as a development tool Allow website designers and programmers to test their work on their own
computers without any access to the Internet. In practice, however, XAMPP is sometimes used to actually serve web pages on
the World Wide Web.
Support for creating and manipulating database in MySQL and SQLite
Download at: http://www.apachefriends.org/en/index.html
http://www.apachefriends.org/en/xampp.html
http://www.apachefriends.org/en/xampp-windows.html
http://en.wikipedia.org/wiki/XAMPP
![Page 20: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/20.jpg)
20
XAMPP Control Panel
![Page 21: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/21.jpg)
21
Running *.html and *.php files
![Page 22: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/22.jpg)
22
localhost/index.php
![Page 23: PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University](https://reader035.vdocuments.us/reader035/viewer/2022062422/56649ee55503460f94bf57c5/html5/thumbnails/23.jpg)
23
localhost/index.html