11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoC H A P T E R 9• • •Strings and Regular ExpressionsProgrammers build applications based on established rules regarding the classification, parsing, storage,and display of information, whether that information consists of gourmet recipes, store sales receipts,poetry, or anything else. This chapter introduces many of the <strong>PHP</strong> functions that you’ll undoubtedly useon a regular basis when performing such tasks.This chapter covers the following topics:• Regular expressions: <strong>PHP</strong> has long supported two regular expressionimplementations known as Perl and POSIX. Although the POSIX implementationwas deprecated in version 5.3.0, I’ve no<strong>net</strong>heless retained the section on the topicfor this edition because you may need to understand how to convert legacy codeto the Perl implementation. You’ll also learn all about <strong>PHP</strong>’s Perl-based regularexpression implementation, now the language’s sole officially supported regularexpression syntax.• String manipulation: <strong>PHP</strong> is the Slap Chop TM of string manipulation, allowing youto slice and dice text in nearly every conceivable fashion. Offering nearly 100native string manipulation functions, and the ability to chain functions together toproduce even more sophisticated behaviors, you’ll run out of programming ideasbefore exhausting <strong>PHP</strong>’s capabilities in this regards. In this chapter, I’ll introduceyou to several of the most commonly used manipulation functions <strong>PHP</strong> has tooffer.• The PEAR Validate_US package: In this and subsequent chapters, various PEARpackages are introduced that are relevant to the respective chapter’s subjectmatter. This chapter introduces Validate_US, a PEAR package that is useful forvalidating the syntax for items commonly used in applications of all types,including phone numbers, Social Security numbers (SSNs), ZIP codes, and stateabbreviations. (If you’re not familiar with PEAR, it’s introduced in Chapter 11.)Regular ExpressionsRegular expressions provide the foundation for describing or matching data according to defined syntaxrules. A regular expression is nothing more than a pattern of characters itself, matched against a certainparcel of text. This sequence may be a pattern with which you are already familiar, such as the word dog,or it may be a pattern with specific meaning in the context of the world of pattern matching, .*, for example.If you are not already familiar with the mechanics of general expressions, please take some time toread through the short tutorial that makes up the remainder of this section. However, because191

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!