-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,247
  • 4
  • 29
  • 43

1 Answers1

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

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

Explosion Pills
  • 183,406
  • 48
  • 308
  • 385