PCREFilter.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Sveta A. Smirnova                          *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     final class PCREFilter implements Filtrator
00016     {
00017         private $search     = null;
00018         private $replace    = null;
00019         private $limit      = -1;
00020         
00024         public static function create()
00025         {
00026             return new self;
00027         }
00028         
00032         public function setExpression($search, $replace)
00033         {
00034             $this->search   = $search;
00035             $this->replace  = $replace;
00036             
00037             return $this;
00038         }
00039         
00040         public function apply($value)
00041         {
00042             return
00043                 preg_replace(
00044                     $this->search,
00045                     $this->replace,
00046                     $value,
00047                     $this->limit
00048                 );
00049         }
00050         
00054         public function setLimit($limit)
00055         {
00056             $this->limit = $limit;
00057             
00058             return $this;
00059         }
00060     }
00061 ?>