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.
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 ...