Skip to Content
Web Database Applications with PHP and MySQL, 2nd Edition
book

Web Database Applications with PHP and MySQL, 2nd Edition

by Hugh E. Williams, David Lane
May 2004
Intermediate to advanced
820 pages
24h 34m
English
O'Reilly Media, Inc.
Content preview from Web Database Applications with PHP and MySQL, 2nd Edition

Regular Expressions

In this section, we show how regular expressions can achieve more sophisticated pattern matching to find, extract, and replace complex substrings within a string. While regular expressions provide capabilities beyond those described in the last section, complex pattern matching isn't as efficient as simple string comparisons. The functions described in the previous section are more efficient than those that use regular expressions and should be used if complex pattern searches aren't required.

This section begins with a brief description of the POSIX regular expression syntax. This isn't a complete description of all of the capabilities, but we do provide enough details to create quite powerful regular expressions. The second half of the section describes the functions that use POSIX regular expressions. Examples of regular expressions can also be found in Chapter 9.

Regular Expression Syntax

A regular expression follows a strict syntax to describe patterns of characters. PHP has two sets of functions that use regular expressions: one set supports the Perl Compatible Regular Expression (PCRE) syntax, and the other supports the POSIX extended regular expression syntax. In this book, we use the POSIX functions.

To demonstrate the syntax of regular expressions, we introduce the function ereg( ) :

boolean ereg(string pattern, string subject [, array var])

ereg( ) returns true if the regular expression pattern is found in the subject string. We discuss how the ereg( ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Web Database Applications with PHP, and MySQL

Web Database Applications with PHP, and MySQL

Hugh E. Williams, David Lane
Learning PHP and MySQL

Learning PHP and MySQL

Michele E. Davis, Jon A. Phillips

Publisher Resources

ISBN: 0596005431Supplemental ContentErrata Page