11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 9 • STRINGS AND REGULAR EXPRESSIONSwww.it-ebooks.info\D: Matches a nondigit character.\s: Matches a whitespace character.\S: Matches a nonwhitespace character.[]: Encloses a character class.(): Encloses a character grouping or defines a back reference.$: Matches the end of a line.^: Matches the beginning of a line.^: Matches any character except for the newline.\: Quotes the next metacharacter.\w: Matches any string containing solely underscore and alphanumeric characters.This is the same as [a-zA-Z0-9_].\W: Matches a string, omitting the underscore and alphanumeric characters.Let’s consider a few examples. The first regular expression will match strings such as pisa and lisabut not sand:/sa\b/The next returns the first case-insensitive occurrence of the word linux:/\blinux\b/iThe opposite of the word boundary metacharacter is \B, matching on anything but a wordboundary. Therefore this example will match strings such as sand and Sally but not Melissa:/sa\B/The final example returns all instances of strings matching a dollar sign followed by one or moredigits:/\$\d+\g<strong>PHP</strong>’s Regular Expression Functions (Perl Compatible)<strong>PHP</strong> offers eight functions for searching and modifying strings using Perl-compatible regularexpressions: preg_filter(), preg_grep(), preg_match(), preg_match_all(), preg_quote(),preg_replace(), preg_replace_callback(), and preg_split(). These functions are introduced in thefollowing sections.Searching an ArrayThe preg_grep() function searches all elements of an array, returning an array consisting of all elementsmatching a certain pattern. Its prototype follows:200

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

Saved successfully!

Ooh no, something went wrong!