Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Need help using preg_replace

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
Haha no way, that's a perfect solution...exactly what I needed!

Thank you very much. :)
 
0
Close
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
Close
glad to be of service!
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back