WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Filter - A simple class that lets you use multiple functions to create custom filters.
Categories : PHP, PHP Classes, Strings Click here to Update Your Picture
Zak Greant
Date : Feb 14th 2001
Grade : Be the 1st to grade this Code Example
Viewed : 6212
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Zak Greant
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?php
class filter
{
var $functions;
var $separator;

function filter ()
{
$this->functions = func_get_args ();

is_array ($this->functions)
or die ('<b>Filter Class Error Message:</b><br>
<br> You must provide at least one argument for
the filter class constructor.<br><br> <font
color="#ffcc00">For example:</font> $my_filter
= new filter ("trim")<br> For more complete
examples, please see the documentation included
with this class.<br>');

foreach ($this->functions as $function)
{
function_exists ($function)
or die ("<b>Filter Class Error Message:</b>
<br><br> The function named <b>$function</b>
is not defined.");

@ $function ('');
! isset ($php_errormsg)
or die ("<b>Filter Class Error Message:</b>
<br><br> There was a problem with the
function named <b>$function</b>, that you
passed to the constructor.<br>When I tested
the function to check if it would accept one
argument, it returned this error:<br>
$php_errormsg");
}

reset ($this->functions);

$this->set_separator ();
}

function apply ($data)
{
if ( ! is_array ($data))
{
foreach ($this->functions as $function)
$data = $function ($data);
}
return $data;

foreach ($data as $key => $value)
foreach ($this->functions as $function)
$data[$key] = $function ($value);
return $data;
}

function output ($data)
{
$data = $this->apply ($data);
print is_array ($data)
? implode ($this->separator, $data) : $data;
return true;
}

function set_separator ($separator = ' ')
{
$this->separator = $separator;
return true;
}
}

/*
DESCRIPTION
============================================================
Filter:
A simple class that lets you create custom filters from
multiple functions and apply these filters to scalar
variables or arrays.
============================================================

CREDITS
============================================================
Author: J. A. Greant ( zak@nucleus.com )
Version 1: May 27, 2000
============================================================

NOTICES
============================================================
If you:
Modify this code and want to share your changes :)
Find a bug
Have other questions or comments

Please write:
Zak Greant (zak@nucleus.com)
============================================================

USAGE EXAMPLES
============================================================
// Make sure to include the filter class in your source code
include ('/path/to/filter.inc');

// Create a new filter
$my_filter = new filter ('trim', 'strrev', 'ucwords');

// Set up some sample data
$original = " Hello Jimmy \n";

// Apply the filter to your sample data
$modified = $my_filter->apply ($original);

// Output the filtered data
$my_filter->output ($original);
============================================================

USAGE NOTES
============================================================
The filter class has a default constructor and three
methods.

The filter Constructor
----------------------
The constructor accepts one or more arguments. Each
argument should be a string that is the name of a valid
function. The functions that you pass to the constructor
should accept a single scalar as an argument. it is best to
use functions like trim or addslashes that perform simple
modifications on string data and return the modified data.
The constructor checks the function names passed to it to
ensure that the function exists and can accept a single
scalar variable as an argument. If either of these tests
fails, the script trying to instantiate the class will
exit. An error message indicating the nature of the problem
will be displayed.
If no errors are generated, then the function names will be
stored by class for later use by the apply and output
methods.

Example: $my_filter = new filter ('trim', 'htmlentities');

The apply Method
----------------
Apply accepts a single scalar or array as an argument. The
method operates by applying each function stored by the
class to the argument that was passed to it. The functions
will be applied to the argument in the order that they were
passed to the constructor.

Example:
$my_filter = new filter ('trim', 'reverse', 'ucwords');
$original = " Hello Jimmy \n";
$modified = $my_filter->apply ($original);

$modified will now contain: Ymmij Olleh

The output Method
-----------------
The output method works very much like apply. The major
differences are that output prints the modified value
instead of returning it - and - if an array is passed to
this method, then it is joined into a string before being
printed. Each element in the array will be separated by
a single space.

Examples:
$my_filter = new filter ('trim', 'reverse', 'ucwords');
$original = " Hello Jimmy \n";
$my_filter->output ($original);
// The above line will print: Ymmij Olleh

$array = array ('Hello','Jimmy');
$my_filter->output ($array);
// The above line will print: Ymmij Olleh

The set_separator Method
------------------------
This method allows you to set the character (or characters)
that separate array elements when an array is printed out
with the output method. The default character is a single
space.

Example:
$array = array ('Hello','Jimmy');
$my_filter->output ($array);
// The above line will print: Ymmij Olleh

$my_filter->set_separator ('&');
$my_filter->output ($array);
// The above line will print: Ymmij&Olleh
============================================================

!!WARNINGS!!
============================================================
The functions that you use to create your new filter MUST:
Accept only **one** argument.

The functions that you use to create your new filter SHOULD:
Accept a string as their argument.
Return a string.

error_tracking should be set to On in your php.ini file
============================================================

COPYRIGHT
============================================================
Copyright (c) 2000 J. A. Greant ( zak@nucleus.com )
All rights reserved.

This library is free software; you can redistribute it
and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation;
either version 2.1 of the License, or (at your option) any
later version.

This library is distributed in the hope that it will be
useful,but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to
the:
Free Software Foundation, Inc.
59 Temple Place, Suite 330
Boston, MA
02111-1307 USA
http://www.gnu.com/
============================================================
*/
?>



Class TStringList include some metods from class TStringList implemented in INPRISE/BORLAND-DELPHI
Categories : PHP Classes, PHP, Strings
STR - a Perl-like string manipulator class - The str class provides 4 perl-like methods for manipulating strings and other scalar variables.
Categories : PHP, PHP Classes, Perl, Strings
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
Formatting a number
Categories : PHP, PHP Classes, Strings
PHP5 URL Object
Categories : PHP, PHP Classes, URLs, Strings
Simple Email address validation
Categories : Email, PHP, Strings
How to find the name of the current file?
Categories : PHP, Filesystem, Strings
PHP Class to calculate Degrees Minutes Seconds to Decimal Degrees
Categories : PHP, PHP Classes, Geo Related, Beginner Guides
Reflection Examples - Their main goal is show how to use PHP's reflection classes re-implementing some php standard functions using reflection.
Categories : PHP, PHP Classes, Classes and Objects
Look for the *position* of the first occurence of string2 in string1, beginning at position start.
Categories : Complete Programs, PHP, Strings
logger class (PHP5 +)
Categories : PHP, PHP Classes, Log Files, XML
Class: Info on Users, Servers and the running script
Categories : PHP, Classes and Objects, User Interface, PHP Classes
XTemplate, a template class for PHP
Categories : PHP Classes, HTML and PHP, PHP
Create HTML forms dynamicly using Javascript & PHP
Categories : PHP, PHP Classes, Java Script
Simple Template Class/Example
Categories : PHP, Templates, PHP Classes