Here is what I want to do:

Search and replace words via an array, like:

$s[]="this";
$r[]="that";

str_replace($s, $r, $string);

But I am having a problem because I need it to be case insensitive and I also need to still replace the word if there is say a period or exclamation point after or before it. I know I'm going to have to use REGEX but I don't know how to use REGEX worth a damn, can someone give me some sample code to work with? I'm already tried the PHP manual and all and didn't find much to work with.

Thanks in advance!

    From php.net... under str_ireplace (not implemented yet until 5.0 is released unless you are running the CVS/beta version :p)

    <?
    function stri_replace($find,$replace,$string)
    {
           if(!is_array($find)) $find = array($find);
           if(!is_array($replace))
           {
                   if(!is_array($find)) $replace = array($replace);
                   else
                   {
                           // this will duplicate the string into an array the size of $find
                           $c = count($find);
                           $rString = $replace;
                           unset($replace);
                           for ($i = 0; $i < $c; $i++)
                           {
                                   $replace[$i] = $rString;
                           }
                   }
           }
           foreach($find as $fKey => $fItem)
           {
                   $between = explode(strtolower($fItem),strtolower($string));
                   $pos = 0;
                   foreach($between as $bKey => $bItem)
                   {
                           $between[$bKey] = substr($string,$pos,strlen($bItem));
                           $pos += strlen($bItem) + strlen($fItem);
                   }
                   $string = implode($replace[$fKey],$between);
           }
           return($string);
    }
    
    //For example:
    $foobar = 'FoO FOO foo bAr BAR bar';
    echo stri_replace(array('foo','bar'),'woggle',$foobar);
    
    // echos 'woggle woggle woggle woggle woggle woggle'
    ?>
    
      Write a Reply...