PHP
  Home arrow PHP arrow Sanitizing Strings with Filters in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Sanitizing Strings with Filters in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-09-02


    Table of Contents:
  • Sanitizing Strings with Filters in PHP 5
  • Review: the FILTER_VALIDATE_IP filter
  • Sanitizing strings with the filter library
  • Sanitizing email addresses, integers and float numbers

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Sanitizing Strings with Filters in PHP 5
    ( Page 1 of 4 )

    Welcome to the eighth part of a nine-part series on using filters in PHP 5. In this part, I discuss how to use the filter extension for sanitizing strings in all sorts of clever manners. I'll show you how to encode quotes, low and high ASCII characters in literals, and remove them in the same easy manner. Doing this can help prevent SQL injections and XSS attacks when developing PHP applications.

    In case you haven’t heard about it yet, the filter extension that comes included with PHP 5 is a powerful library that allows you to perform all sorts of clever validation tasks on incoming data, ranging from checking integers and float numbers, Boolean and string values, to accomplishing more complex processes, such as verifying IP and email addresses.

    Thus, if you’re a PHP developer who’s looking for an approachable guide that shows you how to work with the most relevant filters that come bundled with this useful extension, then you've come to the right place. In this group of articles you’ll find numerous examples that will show you how to get the most out of this data checking library in a truly effortless manner.

    And now that you know the main goal of this article series, it’s time to refresh the topics covered in the last installment. So, as you’ll possibly recall, in that tutorial I discussed the usage of the FILTER_VALIDATE_IP filter for validating IP addresses utilizing both the IPv4 and the IPv6 protocols.

    As with other filters that were reviewed in previous articles of this series, the FILTER_VALIDATE_IP filter was used in conjunction with the already familiar “filter_var()” function, to perform the validation process in a pretty straightforward fashion. However, as I stated previously, the filter extension has plenty of room to let developers verify different data types; this includes the ability to sanitize strings in different ways.

    For instance, say that you need to strip unwanted HTML tags from data collected through a web form, or even wish to replace certain characters in a literal form by their corresponding HTML entities, as you’ve done probably hundreds of times before when using the “html_special_chars()” PHP native function. Well, the filter extension permits you to perform this kind of string sanitization and many, many others.

    Therefore, in this penultimate part of this series, I’m going to explain how to use the extension to “heal” your strings in a snap, without having to code a complex custom function or class methods. So, let’s leave the preliminaries and see how to accomplish these task by means of a few comprehensive examples. Let’s get going!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek