1

Possible Duplicate:
PHP - regex to allow letters and numbers only

First sorry for my bad English. I have question.

I have a string (it's only an example)

$string = 'on"c,e. //up!@#on$# a @#ti'][;me 2012';

What do I need to do, to make the string look like:

$string_after_clean_up = 'once upon a time 2012';

I need to remove all the symbols except letters/numbers and spaces. I was trying with preg_mach() but I failed.

Community
  • 1
  • 1

1 Answers1

5

$string_after_clean_up = preg_replace("/[^a-z0-9\s]/i", "", $string); $string_after_clean_up = preg_replace("/\s\s+/", " ", $string_after_clean_up);

Colin M
  • 13,010
  • 3
  • 38
  • 58