This example uses strip_tags() to delete all
HTML tags from a string:
$input = "Email
spammer@example.com";
echo strip_tags($input);
?>
260 CHAPTER 9 ?– STRINGS AND REGULAR EXPRESSIONS
This returns the following:
Email spammer@example.com
The following sample strips all tags except the
tag:
$input = "This exampleis
awesome!";
echo strip_tags($input, "
");
?>
This 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 Functions
When you??™re processing large amounts of information, the regular expression functions
can slow matters dramatically. You should use these functions only when you are
interested in parsing relatively complicated strings that require the use of regular expressions.
If you are instead interested in parsing for simple expressions, there are a variety
of predefined functions that speed up the process considerably. Each of these functions
is described in this section.
Tokenizing a String Based on Predefined Characters
The strtok() function parses the string based on a predefined list of characters. Its
prototype follows:
string strtok(string str, string tokens)
CHAPTER 9 ?– S TRINGS AND REGULAR EXPRESS IONS 261
One oddity about strtok() is that it must be continually called in order to completely
tokenize a string; each call only tokenizes the next piece of the string.
Pages:
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337