Download presentation
Presentation is loading. Please wait.
Published byEthan Richards Modified over 8 years ago
1
1 Server Side scripting PHP
2
2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) PHP is an open source software (OSS) PHP is free to download and use
3
3 What is a PHP File? PHP files may contain text, HTML tags and scripts PHP files are returned to the browser as plain HTML (View source would not work here!) PHP files have a file extension of ".php", ".php3", or ".phtml"
4
4 Why PHP? PHP runs on different platforms (Windows, Linux, Unix, etc.) PHP is compatible with almost all servers used today PHP is FREE to download from the official PHP resource: www.php.netwww.php.net PHP is easy to learn and runs efficiently on the server side
5
5 Hello world example PHP code can be placed anywhere in the document. Starts and ends with Each code line in PHP must end with a semicolon
6
6 Comments <?php //This is a comment /* This is a comment block */ ?>
7
7 Variables in PHP All variables in PHP start with a $ sign symbol. Variables may contain strings, numbers, or arrays. To concatenate two or more variables together, use the dot (.) operator <?php $txt1="Hello World"; $txt2="1234"; echo $txt1. " ". $txt2 ; ?> The result would be: “Hello World 1234” Rest of operators- same as in JS.
8
8 Flow Control- if-else <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; else echo "Have a nice day!"; ?>
9
9 Flow Control- Switch <?php switch ($x) { case 1: echo "Number 1"; break; case 2: echo "Number 2"; break; default: echo "No number between 1 - 2"; } ?>
10
10Arrays Numeric array - An array with a numeric ID key $names = array("Peter","Quagmire"); $names[0] = "Peter"; $names[1] = "Quagmire"; Associative array - An array where each ID key is associated with a value $ages = array("Peter"=>32, "Quagmire"=>30); $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; Multidimensional array - An array containing one or more arrays
11
11Loops while ; do...while; for; foreach <?php $arr=array("one", "two", "three"); foreach ($arr as $value) { echo "Value: ". $value. " "; } ?>
12
12Functions In PHP - there are more than 700 built-in functions available. We will now show how to how to create your own function <?php function add($x,$y) { $total = $x + $y; return $total; } echo "1 + 16 = ". add(1,16) ?>
13
13 PHP Form Handling Get Vs. Post $_POST example: Enter your name: Enter your age: Welcome. You are years old! Welcome.php
14
14 PHP Sending E-mails mail(to,subject,message,headers,parameters) mail example: <?php $to = "someone@example.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "someonelse@example.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>
15
15 Accessing MySQL DB using PHP <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: '.mysql_error()); } mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM person"); while($row = mysql_fetch_array($result)) { echo $row['FirstName']. " ". $row['LastName']; echo " "; } mysql_close($con); ?> IDFnameLnameAge 1HaimCohen40 2IsraelAharony 46 3NirZuk35
16
16 The End! These slides are based on: http://www.w3schools.com/php/default.asp
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.