XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
StringReplacementFilter.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of SwiftMailer.
5  * (c) 2004-2009 Chris Corbyn
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 
11 //@require 'Swift/StreamFilter.php';
12 
19 {
20 
22  private $_search;
23 
25  private $_replace;
26 
32  public function __construct($search, $replace)
33  {
34  $this->_search = $search;
35  $this->_replace = $replace;
36  }
37 
43  public function shouldBuffer($buffer)
44  {
45  $endOfBuffer = substr($buffer, -1);
46  foreach ((array) $this->_search as $needle)
47  {
48  if (false !== strpos($needle, $endOfBuffer))
49  {
50  return true;
51  }
52  }
53  return false;
54  }
55 
61  public function filter($buffer)
62  {
63  return str_replace($this->_search, $this->_replace, $buffer);
64  }
65 
66 }