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

Introduction to PHP

Covers Chapter 1 of the Textbook
by

Ian Lasky

on 31 August 2016

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Introduction to PHP

Resources
Why PHP?
Constants, etc.
Syntax
ian.lasky@rcc.edu
What is PHP?
Official site for PHP
PHP
originally stood for
P
ersonal
H
ome
P
age.
Created in 1994 by Rasmus Lerdorf to track visitors to his professional web site.
PHP is in version 7 right now.
We are using 5.6.X
The reason why this is important is because the language changes based on the version.
5.0 - 5.5 and 7.0 and up have different syntax to reflect different functionality.

PHP is a server-side language that is interpreted by the browser as it runs. So you will have to run PHP using a web server.

There are lots of companies and organizations that create free servers for you to use.

We use XAMP. There are also MAMP and LAMP servers. The difference is in how it is set up and what platform you are on.

You need a web server, a text editor, and a browser to run PHP.
Basic Syntax
constants are
defined using the define function
PHP Rocks
Ian Lasky
Welcome to CIS 12
My Qualifications
T
eaching since 2005
M
aster's Degree in Computer Science
T
eaching at RCC since 2014
Prerequisites?
This class only has advisory prerequisites.
Having experience with
C++, Java, or any other language helps,
but it's not required to take this class
I teach from a beginner's perspective (from the ground up).


PHP.net
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Basic PHP Page</title>
</head>
<body>
<!-- Script 1.2 - first.php -->
<p>This is standard HTML.</p>
<?php
?>
</body>
</html>
Quotation Mark
Escape Sequences uses a single back
slash to print the string literal
\" prints "
\' prints '
\$ prints $
\n prints a newline
Now, it is understood by what it does:
H
ypertext
P
re
p
rocessor
What is the Version?
How do I use PHP?
MySQL.com
Official site for MySQL
Documentation
This is a basic
HMTL
page with no actual
PHP
in it. This example is coded in
HTML
. The
PHP code
would go in the area in red below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Using Echo</title>
</head>
<body>
<!-- Script 1.2 - first.php -->
<p>This is standard HTML.</p>
<?php
echo 'This sentence was generated using PHP. PHP forever!';
?>
</body>
</html>
This is a basic
HMTL
page with
PHP
in it. This example is coded in
HTML
. The
PHP code
would go in the area in red below. I have also changed the title of the web page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Using Echo</title>
</head>
<body>
<!-- Script 1.2 - first.php -->
<p>This is standard HTML.</p>
<?php
echo 'This sentence was
<p>
generated using
<b>
PHP. PHP forever!
</b></p>
';
?>
</body>
</html>
You can also use
HTML
inside of the
PHP
tags.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Using Echo</title>
</head>
<body>
<!-- Script 1.2 - first.php -->
<p>This is standard HTML.</p>
<?php
# CIS 12; Ian Lasky; Last Updated 8/22/16
# This program displays text to the screen.
# This is my first ever PHP script. Isn't this nice?
//echo is a statement that prints to the screen
/*****I could have used print instead but I wanted to be fancy****/
echo 'This sentence was
<p>
generated using
<b>
PHP. PHP forever!
</b></p>
';
?>
</body>
</html>
Now add
comments
. A
comment
is anything after a hashtag, double slashes, or a slash and a star
More Syntax
A
variable
is denoted by using the
dollar sign
and then a word. The kind of variable is decided when the variable is initialized.
$variable
$a_variable
$_avariable
Variables are used for integers, Boolean, floating point, strings, arrays, objects, and resources
variable
$a variable
$1variable
correct use
incorrect use
Single Quote or Double Quote?
Single Quote
Variables are case sensitive.
$var
!=
$Var
used in
assignment
statements
Double Quote
used in
echo statements
$var = 'text';
echo "hi $var";
String Concatenation
Done with the concatenation operator which is a period (.)

The assignment operator (.=) is also used to concatenate
$city = 'Seattle';
$state = 'Washington';
$address = '$city' . '$state'
$address = '$city' . ',' . $state'
$title = $title . $subtitle;
$title .= $subtitle
Numbers and Math Functionality
Same operators as in C++; (See Pg. 23)
They are defined then changed after the assignment.
$n = 1234;
$n = number_format ($n)
//displays 1,234
$n = 1234;
$n = number_format ($n, 2)
//displays 1,234.00
define ('NAME', value);
Full transcript