Source for file regex_replace.php

Documentation is available at regex_replace.php

  1. <?php
  2.  
  3. /**
  4.  * Replaces the search string by the replace string using regular expressions
  5.  * <pre>
  6.  *  * value : the string to search into
  7.  *  * search : the string to search for, must be a complete regular expression including delimiters
  8.  *  * replace : the string to use as a replacement, must be a complete regular expression including delimiters
  9.  * </pre>
  10.  * This software is provided 'as-is', without any express or implied warranty.
  11.  * In no event will the authors be held liable for any damages arising from the use of this software.
  12.  *
  13.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  14.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  15.  * @license    http://dwoo.org/LICENSE   Modified BSD License
  16.  * @link       http://dwoo.org/
  17.  * @version    1.0.0
  18.  * @date       2008-10-23
  19.  * @package    Dwoo
  20.  */
  21. function Dwoo_Plugin_regex_replace(Dwoo $dwoo$value$search$replace)
  22. {
  23.     $search = (array) $search;
  24.     $cnt count($search);
  25.  
  26.     for ($i 0$i $cnt$i++{
  27.         // Credits for this to Monte Ohrt who made smarty's regex_replace modifier
  28.         if (($pos strpos($search[$i]"\0")) !== false{
  29.             $search[$isubstr($search[$i]0$pos);
  30.         }
  31.  
  32.         if (preg_match('#[a-z\s]+$#is'$search[$i]$m&& (strpos($m[0]'e'!== false)) {
  33.             $search[$isubstr($search[$i]0-strlen($m[0])) str_replace(array('e'' ')''$m[0]);
  34.         }
  35.     }
  36.  
  37.     return preg_replace($search$replace$value);
  38. }

Documentation generated on Sat, 18 Jul 2009 21:05:18 +0200 by phpDocumentor 1.4.0