Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

PHP Intro

An introduction to the PHP server-side scripting language.
by

Richard McKenna

on 26 June 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of PHP Intro

PHP Intro
What is PHP?
A server-side scripting language
PHP References
Home Site
http://us.php.net/

w3schools Tutorial
http://www.w3schools.com/php/

w3schools Quiz
http://www.w3schools.com/php/php_quiz.asp
PHP Files
.php

Can contain:
text
HTML
JavaScript code
PHP code

PHP code:
executed on server
result returned to browser as plain HTML
What can PHP do?
Generate dynamic page content

Read/Write From/To server files

Collect form data

Send and receive cookies

Read/Write From/To database

Restrict page/site access

Encrypt data
What do you need?
Web host with PHP/MySQL support


Locally:
Install a web server
Install PHP and MySQL
Basic PHP Syntax
<?php
// PHP code goes here
?>
echo
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "<h2>Hello World!</h2>";
?>
</body>
</html>
PHP Comments
<!DOCTYPE html>
<html>
<body>
<?php
//This is a PHP comment line
/* This is a PHP
comment block */
?>
</body>
</html>
$variables
No type declarations

Created upon assignment

<?php
$x=5;
$y=$x + 6;
echo $y;
?>
$Variable Scopes
<?php
$x=5; // global scope

function myTest()
{
global $x = 19;
$y=$x+6; // local scope
echo $y;
}

myTest();
?>
$GLOBALS
<?php
$x=5;
$y=10;

function myTest()
{
$GLOBALS['y']=$GLOBALS['x']+$GLOBALS['y'];
}

myTest();
echo $y;
?>
static scope
<?php
function myTest()
{
static $x=0;
echo $x;
$x++;
}
...
parameters
<?php

function myTest($x)
{
echo $x;
}

myTest(5);

?>
Declaring Strings
<?php
$txt="Hello world!";
echo $txt;
?>
. string concatenation
<?php
$txt1="Hello world!";
$txt2="What a nice day!";
echo $txt1 . " " . $txt2;
?>
String Functions
chop
chr
crypt
parse_str
strchr
strcmp
strlen
strpos
substr
...
Standard Features
+,-,*,/,%,++, etc.

if, if else, else

switch

while, do while, for, foreach
Arrays
<?php
$cars=array("Volvo","BMW","Toyota");
echo "I like " . $cars[0]
. ", " . $cars[1] . " and " . $cars[2] . ".";
?>

NOTE: count($cars) returns 3
Assoiative Arrays
Think maps
name/value pairs

$age['Peter']="35";
$age['Ben']="37";
$age['Joe']="43";
Loop through a map
<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");

foreach($age as $x=>$x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
Form Handling
$_GET and $_POST

use to retrieve info from forms
PHP Form
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit">
</form>
</body>
</html>
welcome.php
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>!<br>
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
file I/O
fopen() method
-name of file to open
-file mode (r, w, etc.)

fread()/fwrite()
Ex: fwrite
<html>
<body>
<?php
$file = fopen("test.txt","w");
$text = "Hello World. Testing!";
echo fwrite($file, $text);
fclose($file);
?>
</body>
</html>
Full transcript