Need help using preg_replace

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

Shorty

Established Member
Impact
28
I'm using the following sort of PHP script to replace certain things in a given text:

Code:
$replacethis[1] = '/swear word/';
$withthis[1] = '****';

$replacethis[2] = '/different swear word/';
$withthis[2] = '****';

$name5 = preg_replace($replacethis, $withthis, $name4);

Now this works if someone enters "swear word" as name4. But the problem is, it's case sensitive...If they enter "Swear Word", "SWEAR WORD", "SwEaR WoRd" etc...it doesn't pick it up.

So basically I need a preg_replace that takes no notice of case. Is it possible, or have I gone about it the wrong way?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
well since its just a reg exp, im pretty sure all u gotta do to make the reg exp end with i, meaning it shud be something like this

$replacethis[1] = '/swear word/i';

note the big red I
 
1
•••
Haha no way, that's a perfect solution...exactly what I needed!

Thank you very much. :)
 
0
•••
Just on a side note if you don't require sophisticated processing with regular expressions you would be fine with str_replace in this case, and I think the function is ligther than preg_replace
 
0
•••
glad to be of service!
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Truehost — .com domains from $4.99, hosting includedTruehost — .com domains from $4.99, hosting included

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back