[pLog-svn] r5806 - plog/trunk/class/data/filter

oscar at devel.lifetype.net oscar at devel.lifetype.net
Wed Aug 8 16:33:38 EDT 2007


Author: oscar
Date: 2007-08-08 16:33:37 -0400 (Wed, 08 Aug 2007)
New Revision: 5806

Added:
   plog/trunk/class/data/filter/regexpfilter.class.php
Log:
A new filter that removes all characters that are matched by the given regular expression, so for example RegexpFilter::filter( "[^a-zA-Z0-9_\.]" ) would remove all the characters that are not letters, numbers, underscores and dots.


Added: plog/trunk/class/data/filter/regexpfilter.class.php
===================================================================
--- plog/trunk/class/data/filter/regexpfilter.class.php	                        (rev 0)
+++ plog/trunk/class/data/filter/regexpfilter.class.php	2007-08-08 20:33:37 UTC (rev 5806)
@@ -0,0 +1,34 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/data/filter/filterbase.class.php" );
+
+	/**
+	 * Filter that removes all characters that are matched by the given regular expression
+	 */
+	class RegexpFilter extends FilterBase
+	{
+		private $_regexp;
+		
+		/**
+		 * Constructor
+		 *
+		 * @param regexp The regular expression that determines the valid characters. Everything
+		 * else will be filtered out.
+		 *
+		 * There is no need to provide the regular expression delimiters "/".
+		 */
+		function RegexpFilter( $regexp )
+		{
+			$this->FilterBase();
+			
+			$this->_regexp = $regexp;
+		}
+		
+		function filter( $data )
+		{
+			$data = preg_replace( $this->_regexp, '', $data );
+			
+			return( $data );
+		}
+	}
+?>
\ No newline at end of file



More information about the pLog-svn mailing list