This chapter discusses miscellaneous features of PHP that are often needed for advanced PHP programming. This chapter provides information about working with streamsa feature of PHPand about other features, such as regular expressions, date and time functions, building images, and converting between character setsall features provided by PHP extensions.
Beginning with PHP 4.3.0, you can interact with files, processes, programs, or networks using streams. You can open, read, write, copy, rename, and otherwise manipulate local and remote files, including compressed files, and you can pipe information into and out of processes and programs using PHP functions that work with streams. Many stream functions are available, such as fopen(), which opens a file or URL for reading and/or writing data, and proc_open(), which starts a process by executing a command and establishes a pipe to the process that you can use to send and receive information from the process.
Regular expressions enable you to create patterns that you can then compare to text. Regular expressions are powerful mechanisms for testing text for flow control and for validating user input. Perl regular expressions, provided by the PCRE extension that is enabled by default, consist of a string of special characters and text representing general patterns that match text, such as [0-9] that matches any character between 0 and 9. PHP provides several extensions for using regular expressions, such as preg_match() that matches a string to a pattern and returns the matching strings in an array, and preg_replace that replaces a string that matches a pattern with another specified string.
Other important functions provided by PHP allow special handling of dates and times, the creation of images, and the conversion of text from one character set to another. Date and time functions enable you to store any date, including now, and format the date in many ways, taking locale and Daylight Savings Time (DST) into account. The GD extension (not enabled by default) has many functions that enable you to build images, including color images containing text and bar charts. The iconv and mbstring extensions provide function that allow you to convert from one character set to another, such as converting a text string from ISO-8859-15 (Latin 9) to UTF-8. Locales are definitions on how different languages and/or area represent text, date and time, and money. You can use the PHP function setlocale() to switch between locales and select different locales for different locale types.