-1

I have a strings like this:

  hello this is my_string is-very-cool & another stuff

How I can explode(?) my string by all special chars but allowing the spaces, - and _ ?

Any Ideas?

greenbandit
  • 2,267
  • 5
  • 30
  • 44

1 Answers1

3
preg_split('/[^\w -]/', $string)

This will split on anything that isn't a-z, 0-9, _, - or a space.

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405