O'Reilly logo

Learning PHP & MySQL, 2nd Edition by Jon A. Phillips, Michele E. Davis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Exploring PHP

With PHP, MySQL, and Apache installed, you're ready to begin writing code. Unlike many languages, PHP doesn't require complex tools such as compilers and debuggers. In fact, you'll soon see that you can enter PHP directly into your existing HTML documents, and with just a few tweaks, you'll be off and running.

In this chapter, we'll start by showing you how PHP handles simple text, and then move on to basic decision-making. Some really cool things you can do include showing an image based on the current user's browser, and printing a warning message if the user is browsing from an operating system that makes your web site look crummy. All this and more is possible with PHP, which makes these tricks simple.

PHP and HTML Text

It's simple to output text using PHP; in fact, handling text is one of PHP's specialties. We'll begin with detailing where PHP is processed, then look at some of the basic functions to output text, and from there go right into printing text based on a certain condition being true.

Text Output

You'll want to be able to display text easily and often. PHP lets you do that, though you'll need to use proper PHP syntax when creating the code. Otherwise, your browser assumes that everything is HTML and outputs the PHP code directly to the browser. Everything looks like text and code mixed up. This will certainly confuse your users! You can use whichever text editor you like to write your PHP code, including Notepad or DevPHP (http://sourceforge.net/projects/devphp/ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required