SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
May 6, 2005, 21:38 #1
- 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
-
May 6, 2005, 21:44 #2
- 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
-
May 7, 2005, 00:24 #3
- 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);
-
May 7, 2005, 09:28 #4
- 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
-
May 7, 2005, 09:59 #5
- 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