August 2003
Intermediate to advanced
1104 pages
19h 27m
English
PHP allows for a simple model for tokenizing a string. Certain characters, of your choice, are considered separators. Strings of characters between separators are considered tokens. You may change the set of separators with each token you pull from a string, which is handy for irregular strings—that is, ones that aren't simply comma-separated lists.
Listing 22.1 accepts a sentence and breaks it into words using the strtok function, described in Chapter 12. As far as the script is concerned, a word is surrounded by a space, punctuation, or either end of the sentence. Single and double quotes are left as part of the word. Output is shown in Figure 22.1.
<?php /* ** If submitted a sentence, parse ... |
Read now
Unlock full access