Cameron Garnett/Testpage5

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 print data on the screen and the different ways that you can do it.

Sending data to the Browser

In PHP there are two ways you can get what you want to show up on the screen.

first of all is the ECHO command.


VmvIcon Example.png

Example

<!DOCTYPE html>
<html>
<head></head>
<body>
<?php
echo "<h1> echo command </h1>";
echo "I am trying to explain how to use echo";
echo "feel free to leave comments";
echo "Everybody is welcome";
?>
</body>
</html>

In this next example I will add some variables into the sentence to show you how you would output a variables within a string with the echo command.

VmvIcon Example.png

Example

<!DOCTYPE html>
<html>
<head></head>
<body>
<?php
$one = "anything";
$two = "bed";
$three = "phone";
echo "today i don't feel like doing $one";
echo "I just want to lay in my $two";
echo "I dont feel like picking up the $three";
?>
</body>
</html>


VmvIcon Objective.png

ACTIVITY

write the above block of code into notepad ++ and get yourself familiar with using the echo command.

The second way to output to the browser is the print command. It works the same way as the echo command. For example

VmvIcon Example.png

Example

<!DOCTYPE html>
<html>
<head></head>
<body>
<?php
print "<h1> echo command </h1>";
print "I am trying to explain how to use echo";
print "feel free to leave comments";
print "Everybody is welcome";
?>
</body>
</html>


VmvIcon Example.png

Example

<!DOCTYPE html>
<html>
<head></head>
<body>
<?php
$one = "anything";
$two = "bed";
$three = "phone";
print "today i don't feel like doing $one";
print "I just want to lay in my $two";
print "I dont feel like picking up the $three";
?>
</body>
</html>


VmvIcon Objective.png

ACTIVITY

write the above block of code into notepad ++ and get yourself familiar with using the print command.

Be careful so that you don't type "." instead of ";" at the end of a line.

VmvIcon Example.png

Example

<?php
echo 'a'.
$c = 'x';
echo 'b';
echo 'c';
?>

The output is "axbc", because of the dot on the first line.