PHP also comes with a bunch of functions constructed specially for Web development. The first of these is the very cool addslashes() function, which automatically escapes special characters in strings. You should make it a point to run this function on your variables prior to inserting them into a database (or any other application that has trouble with special characters). You can reverse the process with the stripslashes() function, which removes all the backslashes and returns a "clean" string. The htmlentities() and htmlspecialchars() functions automatically convert special symbols (like < and >) into their corresponding HTML representations (< and >). Similarly, the nl2br() function automatically replaces blank lines in a string with the corresponding HTML line break tag . The strip_tags() functions works in the opposite manner, finding and removing all HTML and PHP tags that may be embedded within the string. And that's about all I have. I hope you enjoyed this article, and that it offered you some insight into the massive amount of string processing power at your disposal in PHP4. For more information on any of the functions listed here, take a look at the PHP manual page on strings at http://www.php.net/manual/en/ref.strings.php ...and until next time, stay healthy!
blog comments powered by Disqus |