Regular Expressions

Regular expressions offer a powerful way to test strings for the presence of patterns. They use a language all their own to describe patterns, a language that consists mostly of symbols. PHP has several functions that use regular expressions. You may wish to turn to Chapter 16, which describes regular expressions in detail.

boolean ereg(string pattern, string text, array matches)

The ereg function evaluates the pattern argument as a regular expression and attempts to find matches in the text argument. If the optional matches argument is supplied, each match will be added to the array. TRUE is returned if at least one match is made, FALSE otherwise.

The first element in the matches array, with an index of zero, will contain ...

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites 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.