Forum Moderators: coopster

Message Too Old, No Replies

Preg Replace all except

         

BlackRaven

10:11 pm on Apr 17, 2007 (gmt 0)

10+ Year Member



how do you replace all chars except certain ones, in my case
A-Za-z0-9\-_.?=&:+'
via preg_replace.

eelixduppy

1:42 am on Apr 18, 2007 (gmt 0)



Try something like this:

$pattern = "/[^A-Za-z0-9\-_.?=&:+']/";
$string = preg_replace($pattern,'',$string);

Refer to pattern syntax [php.net] for more information :)

BlackRaven

3:47 am on Apr 18, 2007 (gmt 0)

10+ Year Member



thnx eelixduppy, however i wanted the opposite of that in other words i would like to keep A-Za-z0-9\-_.?=&:+' but strip out the rest.

eelixduppy

10:40 am on Apr 18, 2007 (gmt 0)



Have you tried the script? That is exactly what it does ;)

joelgreen

3:06 pm on Apr 18, 2007 (gmt 0)

10+ Year Member



Just a clarification. Note ^ just after the [
it means "not" when included as first character of the set [].