7.2. Writing to the Browser

Three functions in PHP will send text to the browser: echo, print, and printf. Each does the same thing: They take values and print them to the browser. The printf function allows you to specify the format of the output rather than sending values as-is. I've used print so far in my examples, mostly out of personal preference. I don't usually need the formatting that printf provides. Many older PHP examples you will find on the Web use echo because it existed in PHP/FI. All three functions are discussed in Chapter 8.

It is important to remember everything you write is in the context of a Web browser. Unless you take measures to make it otherwise, your output will be treated as HTML text. If you send text that is HTML ...

Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.