Cameron Garnett/Testpage4

From WikiEducator
Jump to: navigation, search
PHP

Super Quick PHP Tutorial

Introduction | Basic Syntax | Sending Data to the Browser | Comments | Variables | Strings | Functions | Quotes | Debugging | Form


VmvIcon Objectives.png

Learning Objectives

By the end of this page you will know how to set up php and some of the basic syntax used, when you are dealing with php code.

What Do I Need?

To start using PHP, you can:

  • Find a web host with PHP and MySQL support
  • Install a web server on your own PC, and then install PHP and MySQL
  • Use a Web Host With PHP Support

If your server has activated support for PHP you do not need to do anything. Just create some .php files, place them in your web directory, and the server will automatically parse them for you. You do not need to compile anything or install any extra tools. Because PHP is free, most web hosts offer PHP support.

Set Up PHP on Your Own PC

However, if your server does not support PHP, you must:

Basic Syntax

VmvIcon Objective.png

Amazing objectives

By the end of this page you will be able to:

  1. do amazing stuff

Getting Started: A PHP script starts with <?php and ends with ?>:

<?php PHP code goes here ?>


Write this block of code into note pad ++ and save the file as example.html

Icon activity.jpg
Activity

<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>



At the end of each statement or line it is important that you have a semicolon ; that represents the end of a line

Case Sensitive

In PHP classes, functions, and user-defined functions are NOT case-sensitive. For example


VmvIcon Example.png

Example

<!DOCTYPE html>
<html>
<head></head>
<body>

<?php
ecHO "this is an example";
ECho "this is an example";
ECHO "this is an example";

</body>
</html>

All 3 echo statements are true and will work because the echo function is not case-sensitive.
It is different when you are working with a variable name. You must be careful because these are case-sensitive. For example


VmvIcon Example.png

Example

<!DOCTYPE html>
<html>
<head></head>
<body>

<?php
$weather = "rain";
echo "today it is going to " . $weather . ";
echo "tomorrow it is going to" . $WEATHER . ";
echo "yesterday there was nothing but" . $weaTHER . ";
?>

</body>
</html>

Only the first echo statement is true this is because ($weather, $WEATHER and $weaTHER) are treated as 3 different variables.