Capítulo 5. Zend_Filter

Índice

5.1. Zend_Filter
5.1.1. Introduction
5.1.2. Use Cases
5.2. Zend_Filter_Input
5.2.1. Introduction
5.2.2. Theory of Operation
5.2.3. Use Cases

5.1. Zend_Filter

5.1.1. Introduction

Zend_Filter provides a library of static methods for filtering data. For input filtering, you should use Seção 5.2, “Zend_Filter_Input” instead, because it provides a framework for filtering input using the methods provided by this class. However, because Zend_Filter_Input is designed primarily for arrays, Zend_Filter can be useful for filtering scalars, because it behaves like PHP's string functions:

    <?php
    
    $alphaUsername = Zend_Filter::getAlpha('John123Doe');
    
    /* $alphaUsername = 'JohnDoe'; */
    
    ?>
        

5.1.2. Use Cases

In each of these use cases, $value represents an arbitrary scalar value.

Whitelist Filtering:

    <?php
    
    if ($email = Zend_Filter::isEmail($value)) {
        /* $email is a valid email format. */
    } else {
        /* $email is not a valid email format. */
    }
    
    ?>
        

Blind Filtering:

    <?php
    
    $alphaName = Zend_Filter::getAlpha($value);
    
    ?>
        

Blacklist Filtering:

    <?php
    
    $taglessComment = Zend_Filter::noTags($value);
    
    ?>