PHP Index

In order to become familiar with PHP programming structures and commands, we will build various PHP pages. The following assignments will explain PHP commands, provide a link to a working sample, and detail the working sample's PHP code.

Printing

Printing to the browser is accomplished using the print function:

print();

For example: Assignment031


<html>
<head>
<title>print.php</title>
</head>
<body>
<?php

print("I am so happy to be a horned toad!");

print(
"<br><br>");

print(
"My favorite quote is 'In the end there can be only one.'");  

print(
"<br><br>");

echo 
"printing is easy with \"PHP Hypertext Prepocessor\".";
?>

</body>
</html>

The same can be achieved with the echo command, but we will use print() in this class.

Also, be careful printing certain characters like quotation marks ("). Use the backslash character (\) to escape quotations, like this:

print("She said, \"I hate smelly feet.\"");

The backslash character escapes special characters that cause PHP and MySQL to generate errors.

Finally, you can combine items to print by using the period (.). The period is used to concatinate two separate string items. Concatinate is just a fancy word for put together. Here is an example:

print("My best student is ". $student);

In the above example $student is a variable that holds a name. Which brings me to variables.





In JavaScript, we used document.write. For concatination we used the + symbol.