0

I want to split using multiple delimiters including -:|/. Here is my current code:

preg_split( "/ [-:|] /", $body);

Now I have problem with /. Any ideas?

Salman A
  • 262,204
  • 82
  • 430
  • 521
rails_noob
  • 311
  • 2
  • 5
  • 14

3 Answers3

4
preg_split( '~[-:|/]~', $body);

ps: and, I suppose, there should be no spaces around [ ], but it depends on your situation.

Cheery
  • 16,063
  • 42
  • 57
2

To use the delimiting character inside a regular expression, escape it using a \.

preg_split("/ [-:|\\/] /", $body);

Better, you can use other any other delimiter. Various characters will work:

preg_split("@ [-:|/] @", $body);
preg_split("# [-:|/] #", $body);
Salman A
  • 262,204
  • 82
  • 430
  • 521
0
preg_split( "~ [-:/|] ~", $body);
meze
  • 14,975
  • 4
  • 47
  • 52