SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The one time I think I may need to use ereg*

    Alright, here's my question. I have a variable, let's say $blah. Let's pretend (though this isn't the case) that $blah is $_GET["somefing"];

    Now, there's no way I can be sure that $blah will really be a correct RegExp pattern, and I don't want it to be. My question is, how could I do a case insensitive replace of something.

    preg_replace("/stuff/i", "TEH NEW STUFF", $var);

    How can I use anything in stuff's place, even stuff like periods without having to escape them? I don't want to use str_ireplace, it's PHP 5 only and I'm using 4.3.10.
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  2. #2
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, eregi_replace is no good because I want all characters of $blah to be parsed literally, not as regexp patterns.
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  3. #3
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $stuff = (get_magic_quotes_gpc()) ? stripslashes($_GET["somefing"]) : $_GET["somefing"];

    $text preg_replace("/" preg_quote($stuff,"/") . "/i","ALALALALLAAL",$var); 

  4. #4
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a ton, will try this out now
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  5. #5
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works, I didn't know about that preg_quote.


    You learn something new everyday
    I think there needs to be a "Name that function-inator" on the PHP site, I always know it's possible to do something but don't know the name of the function.
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •