Download presentation
Presentation is loading. Please wait.
1
PHP Hypertext Preprocessor
2
Getting Started PHP code starts with <?php and ends with ?>.
The file containing the PHP must have a file extension of .php (not .html) PHP is a server side scripting language. PHP files must reside on the server in order for the PHP script to be executed.
3
Variables PHP is loosely typed. All variables start with a $
The first character following the $ must be a letter or underscore. Variable can only contain letters, digits, underscores
4
Working with Strings The concatenation operator is a dot (.), not a + sign. JavaScript: var name = "Elizabeth " + "Hutchison"; PHP: $name = "Elizabeth " . "Hutchison"; JavaScript: var name = "Mickey"; name += "Mouse"; PHP $name = "Mickey"; $name .= "Mouse";
5
String functions The strlen() function is used to return the length of a string. strpos() function is used to search for character within a string. Returns the starting position of the string or false if string is not found. $filename = "index.php"; strpos($filename, "footer.php"); //returns false strpos($filename, "php"); //returns 6 Note: This function IS case-sensitive!
6
Echoing Variables and Text Strings
Use echo to display echo $filename; echo "Hello world"; echo "Hello" . $filename; echo strpos($filename, "footer.php"); echo strpos($filename, "php");
7
If statement if (condition) statement to be executed if true;
if (condition) {statements to be executed if true;} if (condition) statement to be executed if true; else statement to be executed if false;
8
$_SERVER $_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server.
9
$_SERVER['HTTP_USER_AGENT'] info about user's operating system, as well as their browser.
Try echo $_SERVER['HTTP_USER_AGENT'] ;
10
$_SERVER['SERVER_ADDR] The IP address of the server under which the current script is executing.
$_SERVER['SERVER_NAME'] The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.
11
$_SERVER['SCRIPT_FILENAME'] returns the pathname of the currently executing script.
Try echo $_SERVER['SCRIPT_FILENAME'] ;
12
$_POST $_POST is used to collect values in a form with method="post".
The $_POST array is an associative array of variables passed to the current script via the HTTP POST method. the names (not ids) of the form fields will automatically be the keys in the $_POST array Examples: $pay= $_POST["wage"]; $greeting ="Hello “ . $_POST[“name"]; <?php echo $_POST["major"]; ?>
13
include In PHP, you can insert the content of one PHP file into another PHP file before it is served. The html segment should be valid html. It is not an entire html file, just the segment of html that you want inserted. Syntax: include ('filename‘); Example: <?php include (‘menu.php‘); ?>
14
Java Script tips Shorthand This: Is the same as this
var $ = function(id) { return document.getElementById(id); } $("error_message1").innerHTML = "Oops!"; $("error_message2").innerHTML = "Oops again!"; $("error_message3").innerHTML = “TripleOops!"; Is the same as this document.getElementById("error_message").innerHTML = "Oops!"; document.getElementById("error_message2").innerHTML = "Oops again!"; document.getElementById("error_message3").innerHTML = “TripleOops!";
15
Java Script tips Converting strings to numbers parseInt(x):
Parses a string read from a form to an integer var hours = parseInt($(“hours").value); parseFloat(x) Parses a string read from a form to an floating point number var wage= parseFloat($(“wage").value); isNaN(x) Returns true of x is Not a Number, false if it is a number isNaN(wage) would return true if the user left the wage entry blank or entered text.
16
Java Script tips Spans rock!
Create a span in your html that you can later add text to when an error occurs. $(“wage_error").innerHTML = "*Wage must be greater than 7.25"; Don’t forget you can change the style (css) using script as well. $(“wage_error").style.color = “red"; $(“wage_error").style.backgroundColor = “green"; $(“wage_error").style.fontWeight = "bolder"; $(“wage_error").style.fontSize = "200%"; Etc…..
17
Disabling buttons Html JavaScript
Use disabled Attribute to keep a user from clicking a button disabled="disabled" JavaScript $("submit").disabled=false; $("submit").disabled=true;
18
Lab Time!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.