views:

124

answers:

2

I can get it to remove all the question marks with the code below:

preg_replace('/(\?+)/', '', $string)

No matter what I seem to do I can't get it to also remove all the minus signs as well. Everything I try just breaks the whole regex.

+5  A: 

Maybe

str_replace(array("?",  "-"), "", $string)

Will work more to your liking.

Chacha102
Yeah, this would work but I already know how to do that. I'm attempting to be one step above worthless with regex code
Failpunk
+3  A: 

Either use a string replace, or:

preg_replace('/[-?]/', '', $string)

That will remove any question marks or dashes (minus signs) from your input. Easier to extend to more characters than string replacement, since you can simply add the new character inside the square bracket and be done.

Max Shawabkeh
Yeah, that's what I'm looking for. Replace all - and ? in a string.
Failpunk