PHP
  Home arrow PHP arrow Page 2 - Using 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

Using Filters in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2009-07-15


    Table of Contents:
  • Using Filters in PHP 5
  • Filters available in PHP 5
  • Checking for integer values with the filter PHP extension
  • Using the FILTER_VALIDATE_INT filter to check for minimal and maximal values

  • 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


    Using Filters in PHP 5 - Filters available in PHP 5
    ( Page 2 of 4 )

    Before I start explaining how to use filters in PHP 5, it’s convenient to check which of them comes with the PHP distribution. To do this, I’m going to use a pair of handy native functions called “filter_list()” and “filter_id()." The first one will return an array of the existing filters and the second one will retrieve their corresponding IDs.

    A simple demonstration of how to use these functions is coded below. Take a look at the following example:

    <?php

     

    // example on using the 'filter_list()' function

    foreach(filter_list() as $id => $filter)

    {

    echo '<p> Filter Name: ' . $filter . ' ------------- Filter ID: ' . filter_id($filter) . '</p><hr />';

    }

     

    /* displays the following

     

    Filter Name: int ------------- Filter ID: 257

     

    Filter Name: boolean ------------- Filter ID: 258

     

    Filter Name: float ------------- Filter ID: 259

     

    Filter Name: validate_regexp ------------- Filter ID: 272

     

    Filter Name: validate_url ------------- Filter ID: 273

     

    Filter Name: validate_email ------------- Filter ID: 274

     

    Filter Name: validate_ip ------------- Filter ID: 275

     

    Filter Name: string ------------- Filter ID: 513

     

    Filter Name: stripped ------------- Filter ID: 513

     

    Filter Name: encoded ------------- Filter ID: 514

     

    Filter Name: special_chars ------------- Filter ID: 515

     

    Filter Name: unsafe_raw ------------- Filter ID: 516

     

    Filter Name: email ------------- Filter ID: 517

     

    Filter Name: url ------------- Filter ID: 518

     

    Filter Name: number_int ------------- Filter ID: 519

     

    Filter Name: number_float ------------- Filter ID: 520

     

    Filter Name: magic_quotes ------------- Filter ID: 521

     

    Filter Name: callback ------------- Filter ID: 1024

    */

    ?>

    As you can see in the above code sample, the combined use of the “filter_list()” and “filter_id()” functions provides useful information about the filters that are available with the PHP 5 distribution. In this particular case, the name and ID of each filter is displayed on screen via a simple “foreach” construct, which helps you understand each one's functionality. 

    Of course, from the previous example it’s easy to see that there are filters available for checking integers and float numbers, Boolean values and regular expressions, URLs, email and IP addresses, strings and special characters, and so forth. However, since this will be a progressive process, I’m going to discuss  each filter in detail in successive tutorials of this series.

    At this point you should have some idea of how useful PHP 5 filters can really be for validating incoming data. Therefore, it’s time to start an in-depth discussion of the first filter shown by the previous list. It is the one responsible for checking whether a given value is an integer.

    This brand new PHP 5 filter will be explored in detail in the next segment. Thus, to learn how to work with it, click on the link below and read the next few lines.



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

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - 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...





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