[ Team LiB ] Previous Section Next Section

Hour 18. Working with Regular Expressions

What You'll Learn in This Hour:

  • How to match patterns in strings using regular expressions

  • The basics of regular expression syntax

  • How to replace text in strings using regular expressions

  • How to use regular expressions to split a string into an array

Regular expressions are a powerful way of examining and modifying text. They enable you to search for patterns within a string, extracting matches flexibly and precisely. Be warned that because they are more powerful, they are also slower than the more basic string function examined in Hour 8, "Working with Strings." You should use string functions, therefore, if you don't need the extra power afforded by the use of a regular expression function.

PHP supports two flavors of regular expressions. It has a set of functions that emulate regular expressions as employed in Perl and a set of functions that support the more limited POSIX regular expressions. Because Perl-compatible regular expressions are the more powerful of the two, we will concentrate on them.

    [ Team LiB ] Previous Section Next Section