O'Reilly logo

Learning PHP and MySQL 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 11. Practical PHP

In this chapter, we'll start working on some of the more common tasks that you'll perform when writing PHP programs, such as work with strings, display formats for strings, as well as dates and time. We'll also show you how to work with files that your PHP program creates or reads. Also, we'll provide an example of how to let a user upload a file and then validate its contents before making it accessible. Uploading files is useful but can be a security risk if files aren't properly validated.

When building HTML output for web pages, we spend quite a bit of time working with strings. PHP has a rich set of functions for doing all the tasks you may need to change the case of a string. You also need to be able to format dates and times. Performing any sort of addition or subtraction on dates—thanks to quirks such as leap years—can quickly become complicated without a little help from functions specifically designed to work with dates.

String Functions

Because you're working with essentially two languages that both support manipulating strings, you need to learn about string functions in PHP and MySQL. You may find it more appropriate to modify a string either in a query or in PHP, based on the particular situation. You're going to learn about the following string operations:

  • Formatting strings for display

  • Calculating the length of a string

  • Changing a string's case to uppercase or lowercase

  • Searching for strings within strings and returning the position of the match ...

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