Thestrtr()function converts all characters in a string to their corresponding match found in a predefined array. Its prototype follows: string strtr(string str, array replacements) This example converts the deprecated bold (<b>) character to its XHTML equivalent: <?php This returns the following: -------------------------------------------- Converting HTML to Plain Text You may sometimes need to convert an HTML file to plain text. You can do so using thestrip_tags()function, which removes all HTML and PHP tags from a string, leaving only the text entities. Its prototype follows: string strip_tags(string str [, string allowable_tags]) The optionalallowable_tagsparameter allows you to specify which tags you would like to be skipped during this process. This example usesstrip_tags()to delete all HTML tags from a string: <?php This returns the following: -------------------------------------------- The following sample strips all tags except the<a>tag: <?php This returns the following: -------------------------------------------- Note Another function that behaves like strip_tags()isfgetss(). This function is described in Chapter 10.
blog comments powered by Disqus |
|
|
|
|
|
|
|