str_ireplace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • windandwaves

    str_ireplace

    Does anyone know of a function that works like str_ireplace in PHP < 5?

    str_ireplace(a, b,c) replaces a with b in c, just like str_replace, but case
    insensitive.

    TIA

    - Nicolaas


  • Mike Willbanks

    #2
    Re: str_ireplace

    Nicolaas,
    [color=blue]
    > Does anyone know of a function that works like str_ireplace in PHP < 5?[/color]

    mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [,
    int limit [, int &count]] )

    then just run it with a flag of i. so take your example:

    preg_replace('/b/i', 'a', 'c')

    a better example of this would be:
    $subject = 'this is my MOM';
    $pattern = '/mom/i';
    $replace = 'DAD';
    echo preg_replace($p attern, $replace, $subject);

    [color=blue]
    > str_ireplace(a, b,c) replaces a with b in c, just like str_replace, but case
    > insensitive.[/color]


    --
    Mike Willbanks
    Zend Certified Engineer

    Comment

    • Tobierre

      #3
      Re: str_ireplace

      Hi why don't you just do the following to get the same result?

      $var = strtolower$var) ; //convert string to lower case
      str_ireplace(.. ., $var);

      if you don't want to convert the original string just do

      $var = 'SomE STrinG';

      $testvar = strtolower($var );
      $str_ireplace(. .., $testvar);

      Tobierre

      "windandwav es" <winandwaves@co ldmail.com> wrote in message
      news:H8X6f.2140 $S24.150355@new s.xtra.co.nz...[color=blue]
      > Does anyone know of a function that works like str_ireplace in PHP < 5?
      >
      > str_ireplace(a, b,c) replaces a with b in c, just like str_replace, but
      > case insensitive.
      >
      > TIA
      >
      > - Nicolaas
      >[/color]


      Comment

      Working...