0

I am trying to basically explode a string with both a space and a forward slash. This is what I have:

$array = preg_split("/[\s,\/]+/", $string)

But I think I am doing something wrong. I have searched online but I can't really grasp how you enclose or define the characters. Is space \s? I thought slash forward was / but I am not sure anymore.

Thank you,

user2961763
  • 63
  • 1
  • 9
  • 1
    Works fine [here](http://codepad.org/vRwrudcd) ? – ccKep Apr 29 '14 at 23:46
  • 1
    Your pattern will split on 1 or more `space` `,` or `/` just `explode(' /', $string);` maybe? – AbraCadaver Apr 29 '14 at 23:55
  • Did you want to match multiple spaces and slashes or just a signle space or slash? Maybe try `.` instead of `+` – rmcfrazier Apr 30 '14 at 00:38
  • For example, if I have the string "2 1/2", I want the array to be: [2,1,2]. I tried it on codepad and it does work... I am going to look more into my code to see what's wrong. – user2961763 Apr 30 '14 at 13:56

0 Answers0