PHP
CHAPTERS 5, 12, 13
WHAT IS PHP?
SERVER SIDE SCRIPTING
LANGUAGE
PHP: HYPERTEXT
PREPROCESSOR
CATCH THE RECURSIVE
ACRONYM
• <!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo "Hi, I'm a PHP script!";
?>
</body>
</html>
HOW DO
WE RUN
PHP?
Open in a browser?
Let’s try this and observe
Create hello world PHP program in Atom
Save on local computer as hello.php
Brower File / Open file / hello.php
Observe and explain
HOW DO
WE RUN
PHP?
We need a server!!
XAMPP to the rescue
It is an installation package
Installs PHP, MySQL, and Apache (web server)
Refer to Appendix A of your
textbook
XAMPP for Linux, Windows, Mac
WAMP for Windows
MAMP for Mac
XAMPP
X – cross-platform installation (windows, linux,
mac)
A – apache, M – MySQL, P – PHP, P – Perl
Download from
http://www.apachefriends.org/download.html
Install on your local machine
USING PHP
VIA
APACHE
SERVER
Where to put your
hello.php file?
Google it and
follow the example
Demo on my Mac
Install then run
xampp
NEED HELP?
HTTPS://COMMUNITY.APACHEFRIENDS.ORG/F/
HELLO WORLD DEMO
VIA ATOM
MORE
ABOUT PHP
What distinguishes PHP from something like client-side
JavaScript is that the code is executed on the server,
generating HTML which is then sent to the client.
The client would receive the results of running that script, but
would not know what the underlying code was.
You can even configure your web server to process all your
HTML files with PHP, and then there's really no way that users
can tell what you have up your sleeve.
The best things in using PHP are that it is extremely simple for
a newcomer, but offers many advanced features for a
professional programmer.
PHP INFO EXAMPLE VIA
ATOM
PHP
VARIABLES
• Start with $
• Letters, numbers, _
• Must start with letter or _
• $a
• $a_very_long_variable_name
• $_24563
• Case sensitive!! (but NOTE: keywords
are NOT)
• See
http://localhost:8080/php_variables.ph
p
• See
http://localhost:8080/php_variables.ht
PHP
SYNTAX
• Instructions end with ;
• Comments //
• How do you do comments in html?
• Undefined variable references generate error –
see atom demo
• By default variables are local in scope – limited
to script or function in which defined
• Use “global” to make the global in scope
SUPER GLOBALS
• Some predefined variables in PHP are "superglobals", which means that they
are always accessible, regardless of scope - and you can access them from
any function, class or file without having to do anything special.
• The PHP superglobal variables are:
• $GLOBALS
• $_SERVER
• $_REQUEST
• $_POST
• $_GET
• $_FILES
• $_ENV
• $_COOKIE
• $_SESSION
DEMOS FROM CHAPTERS
5
CHAPTER 5
DEMOS
Embedded condition – version 1
http://localhost:8080/examples/05/embedcondition.ph
p
Embedded condition – version 2
http://localhost:8080/examples/05/embedcondition_v2
.php
DEMOS FROM CHAPTERS
12
CHAPTER
12 DEMOS
Data types - http://localhost:8080/examples/12/testtype.php
•Good idea to test data type to avoid errors
Set type - http://localhost:8080/examples/12/settype.php
Casting - http://localhost:8080/examples/12/casttype.php
Constants - http://localhost:8080/examples/12/constant.php
Arrays - http://localhost:8080/examples/12/mdarray.php
CHAPTER 12
ARRAY
CONSTRUCT
S &
FUNCTIONS
Over 70!!
Pages 322 – 323
https://www.php.net/manual/en/ref.array.php
DEMOS FROM CHAPTERS
13
CHAPTER
13 DEMOS
HTTP://LOCALHOST:80
80/EXAMPLES/13/
DEMO PROGRAMS
• abs • source • execute

Upstate CSCI 450 PHP

  • 1.
  • 2.
    WHAT IS PHP? SERVERSIDE SCRIPTING LANGUAGE PHP: HYPERTEXT PREPROCESSOR CATCH THE RECURSIVE ACRONYM
  • 3.
  • 4.
    HOW DO WE RUN PHP? Openin a browser? Let’s try this and observe Create hello world PHP program in Atom Save on local computer as hello.php Brower File / Open file / hello.php Observe and explain
  • 5.
    HOW DO WE RUN PHP? Weneed a server!! XAMPP to the rescue It is an installation package Installs PHP, MySQL, and Apache (web server) Refer to Appendix A of your textbook XAMPP for Linux, Windows, Mac WAMP for Windows MAMP for Mac
  • 6.
    XAMPP X – cross-platforminstallation (windows, linux, mac) A – apache, M – MySQL, P – PHP, P – Perl Download from http://www.apachefriends.org/download.html Install on your local machine
  • 7.
    USING PHP VIA APACHE SERVER Where toput your hello.php file? Google it and follow the example Demo on my Mac Install then run xampp
  • 14.
  • 15.
  • 16.
    MORE ABOUT PHP What distinguishesPHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was. You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve. The best things in using PHP are that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer.
  • 17.
  • 18.
    PHP VARIABLES • Start with$ • Letters, numbers, _ • Must start with letter or _ • $a • $a_very_long_variable_name • $_24563 • Case sensitive!! (but NOTE: keywords are NOT) • See http://localhost:8080/php_variables.ph p • See http://localhost:8080/php_variables.ht
  • 19.
    PHP SYNTAX • Instructions endwith ; • Comments // • How do you do comments in html? • Undefined variable references generate error – see atom demo • By default variables are local in scope – limited to script or function in which defined • Use “global” to make the global in scope
  • 20.
    SUPER GLOBALS • Somepredefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. • The PHP superglobal variables are: • $GLOBALS • $_SERVER • $_REQUEST • $_POST • $_GET • $_FILES • $_ENV • $_COOKIE • $_SESSION
  • 21.
  • 22.
    CHAPTER 5 DEMOS Embedded condition– version 1 http://localhost:8080/examples/05/embedcondition.ph p Embedded condition – version 2 http://localhost:8080/examples/05/embedcondition_v2 .php
  • 23.
  • 24.
    CHAPTER 12 DEMOS Data types- http://localhost:8080/examples/12/testtype.php •Good idea to test data type to avoid errors Set type - http://localhost:8080/examples/12/settype.php Casting - http://localhost:8080/examples/12/casttype.php Constants - http://localhost:8080/examples/12/constant.php Arrays - http://localhost:8080/examples/12/mdarray.php
  • 25.
    CHAPTER 12 ARRAY CONSTRUCT S & FUNCTIONS Over70!! Pages 322 – 323 https://www.php.net/manual/en/ref.array.php
  • 26.
  • 27.
  • 28.
    DEMO PROGRAMS • abs• source • execute