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.

CHAPTER 9 • STRINGS AND REGULAR EXPRESSIONSwww.it-ebooks.infoAccommodating Products Supporting Solely Case-SensitiveRegular ExpressionsThe sql_regcase() function converts each character in a string into a bracketed expression containingtwo characters. If the character is alphabetical, the bracket will contain both forms; otherwise, theoriginal character will be left unchanged. Its prototype follows:string sql_regcase(string string)You might use this function as a workaround when using <strong>PHP</strong> applications to talk to otherapplications that support only case-sensitive regular expressions. Here’s how you would usesql_regcase() to convert a string:Regular Expression Syntax (Perl)Perl has long been considered one of the most powerful parsing languages ever written. It provides acomprehensive regular expression language that can be used to search, modify, and replace even themost complicated of string patterns. The developers of <strong>PHP</strong> felt that instead of reinventing the regularexpression wheel, so to speak, they should make the famed Perl regular expression syntax available to<strong>PHP</strong> users.Perl’s regular expression syntax is actually a derivation of the POSIX implementation, resulting inconsiderable similarities between the two. You can use any of the quantifiers introduced in the previousPOSIX section. The remainder of this section is devoted to a brief introduction of Perl regular expressionsyntax. Let’s start with a simple example of a Perl-based regular expression:/food/Notice that the string food is enclosed between two forward slashes. Just as with POSIX regularexpressions, you can build a more complex string through the use of quantifiers:/fo+/This will match fo, whether the string appears in isolation or is followed by one or more characters.Some potential matches include food, fool, and fo4. Here is another example of using a quantifier:/fo{2,4}/This matches f followed by two to four occurrences of o. Some potential matches include fool,fooool, and foosball.198

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

Saved successfully!

Ooh no, something went wrong!