Syntax

Opening and closing PHP

Let's look a bit more in depth at what is going on with this statement. Since developers often embed PHP inside html files, the server needs to know where the PHP scripting begins and ends. All PHP code on a page must go between the opening <?php and closing ?>

Semicolon at the End of the Line

All statements, unless otherwise noted, require a semicolon at the end.

The echo Function

PHP has many built in functions that make developing easier. One such function is the echo function. This function takes whatever appears between the word echo and the semicolon at the end of the statement and outputs it to the screen. If you would like to output a string of text, the text must go between quotation marks.

You can use either single or double quotation marks, but they must match:

echo "Jim's Book";
echo 'He said "OK"';

Escaping Quotes

Sometimes you need both single and double quotes. You can escape quotes using the back slash. \" indicates that the quote doesn't count as a quote in PHP syntax. To display the sentence Jim said, "I'm OK." we would write:

  echo 'Jim said, "I\'m OK."';
or echo "Jim said, \"I'm OK.\"";
You should try all of the examples!
INDEX, What do you Need?, Hello World: the first example, Syntax, Debugging, Self-Study Questions
Next lesson: Variables in PHPMAIN INDEX
EXAMPLES INDEX

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Syntax