Upload
sriramadapa
View
106
Download
4
Embed Size (px)
Citation preview
PHP
Sriram A
Introduction
Hypertext Preprocessor. Server-side scripting language. Efficient alternative to competitors such
as Microsoft's ASP . Works on a number of platforms and
supports many databases. Extension -".php", ".php3", or ".phtml"
Basic Syntax
<html><body>
<?phpecho "Hello World"; //This prints Hello world
?>
</body></html>
PHP ignores white space
PHP Variables
Loosely typed language. $var_name = value; case-sensitive
Echo
Echo is a language construct Language construct Vs. Functions
Arrays
In PHP, there are three kind of arrays:• Numeric array - An array with a numeric
index $cars=array("Saab","Volvo","BMW","Toyota");
• Associative array - An array where each ID key is associated with a value
$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);
• Multidimensional array - An array containing one or more arrays
String Creation
Single Quote Double Quote $my_string = “Tizag - Unlock your potential!”; Heredoc - Multi-line strings
PHP Operators and Decision Controls
Operators Assignment Operators Arithmetic Operators Comparison Operators String Operators Combination Arithmetic & Assignment
Operators
If statement Else statement Elseif statement Switch case
Include and Require
Header.php
Footer.php
Page 1 Page 2 Page 3 Page 4
PHP Forms POST and GET
PHP Functions
Loops
PHP Magic Quotes & Stripslashes INPUT: "It's a beautiful day outside and I like
to use \'s."
HTML Entities
Prevents attackers from running html code and scripts that may be harmful to your visitors
Changes the data at three different levels: in PHP, in raw HTML and in the web browser.
PHP Strings
String Position
String Replace
SubString Replace
strtoupper strtolower ucwords
Explode - also has limit
Implode
PHP Sessions
session_start(); $_SESSION associative array isset unset session_destroy();
PHP Cookies
setcookie(name, value, expire, path, domain);
isset() $_COOKIE associative array print_r($_COOKIE);
PHP Files
fopen$ourFileHandle = fopen($ourFileName, 'w') or die("can't
open file");
fclose fread
$fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile));
fwrite and fgets$stringData = "Pointy Pinto\n"; fwrite($fh, $stringData);fgets($fh);
File Unlink unlink($myFile); File upload HTML Form
PHP Code
Thank You