PHP & MySQL® Web Development All-in-One Desk Reference for Dummies®
by Janet Valade, Tricia Ballad, Bill Ballad
1.5. Displaying Content in a Web Page
You display content on your Web page with echo statements. An echo statement produces output, which is sent to the user's browser. The browser handles the output as HTML.
The general format of an echo statement is
echo outputitem,outputitem,outputitem,...
where the following rules apply:
An outputitem can be a number, a string, or a variable (using variables is discussed in the section "Using PHP Variables," later in this chapter. A string must be enclosed in quotes.
List as many outputitems as you need, separated by commas.
Table 1-1 shows some echo statements and their output.
| echo Statement | Output |
|---|---|
| echo "Hello"; | Hello |
| echo 123; | 123 |
| echo "Hello","World!"; | HelloWorld! |
| echo Hello World!; | Not valid; results in an error message |
| echo "Hello World!"; | Hello World! |
| echo 'Hello World!'; | Hello World! |
echo statements output a line of text that's sent to a browser. The browser considers the text to be HTML and handles it that way. Therefore, you need to make sure that your output is valid HTML code that describes the Web page that you want the user to see.
When you want to display a Web page (or part of a Web page) by using PHP, you need to consider three stages in producing the Web page:
The PHP script: PHP echo statements that you write.
The HTML source code: The source code for the Web page that you see when you choose View
Source in your ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access