Chapter 8
Chapter 8
Server-Side
Development with
PHP
Chapter 8
3 Quick Tour of
PHP 4 Program
Control
5 Functions
7
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
Section 1 of 5
WHAT IS SERVER-SIDE DEVELOPMENT
<?php
# single-line comment
/*
This is a multiline comment.
They are a good way to document functions or
complicated blocks of code
*/
$artist = readDatabase(); // end-of-line comment
?>
$count = 42;
$firstName = "Pablo";
$lastName = "Picasso";
/*
Example one:
These two lines are equivalent. Notice that you can reference
PHP variables within a string literal defined with double
quotes. The resulting output for both lines is: <em>Pablo
Picasso</em>
*/
echo "<em>" . $firstName . " ". $lastName. "</em>";
echo "<em> $firstName $lastName </em>";
/*
Example two:
These two lines are also equivalent. Notice that you
can use either the single quote symbol or double quote
symbol for string literals.
*/
echo "<h1>";
echo '<h1>';
/*
Example three:
These two lines are also equivalent. In the second
example, the escape character (the backslash) is used
to embed a double quote within a string literal defined
within double quotes.
*/
echo '<img src="23.jpg" >';
echo "<img src=\"23.jpg\" >";
Sequence Description
\n Line feed
\t Horizontal tab
\\ Backslash
\$ Dollar sign
PROGRAM CONTROL
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
If…else
FUNCTIONS
Randy Connolly and Ricardo Hoar Fundamentals of Web Development
Functions
You mean we don’t write everything in main?
3 Quick Tour of
PHP 4 Program
Control
5 Functions
7
Randy Connolly and Ricardo Hoar Fundamentals of Web Development