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.infoThis returns the following:This example is awesome!■ Note Another function that behaves like strip_tags() is fgetss(). This function is described in Chapter 10.Alternatives for Regular Expression FunctionsWhen you’re processing large amounts of information, the regular expression functions can slowmatters dramatically. You should use these functions only when you are interested in parsing relativelycomplicated strings that require the use of regular expressions. If you are instead interested in parsingfor simple expressions, there are a variety of predefined functions that speed up the processconsiderably. Each of these functions is described in this section.Tokenizing a String Based on Predefined CharactersThe strtok() function parses the string based on a predefined list of characters. Its prototype follows:string strtok(string str, string tokens)One oddity about strtok() is that it must be continually called in order to completely tokenize astring; each call only tokenizes the next piece of the string. However, the str parameter needs to bespecified only once because the function keeps track of its position in str until it either completelytokenizes str or a new str parameter is specified. Its behavior is best explained via an example:// print out each element in the $tokenized arraywhile ($tokenized) {echo "Element = $tokenized";// Don't include the first argument in subsequent calls.$tokenized = strtok($tokens);}This returns the following:Element = J. GilmoreElement = jason@example.com216

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

Saved successfully!

Ooh no, something went wrong!