preg_split with forwardslash

Can a preg_split be accompished with a forwardslash as the seperator. I just tried a test from the PHP Manual and couldn’t get anything to work. (I am trying to split a URL at the slashes)

$keywords = preg_split("/[\\s,]+/", "hypertext language, programming");

changed to..

$keywords = preg_split("/[/]+/", "hypertext language/ programming");

I tried a couple other things but couldn’t get them to work.

Nevermind. I was just missing a backslash.

$keywords = preg_split("/[\\/]+/",
"hypertext language/ programming");

I believe you don’t even need that, just use a different character for your starting and ending delimiters. I haven’t tested this, but it should work:

$keywords = preg_split("X/+X", "hyptertext language/ programming");

worth a shot.

For a single character, preg_split is using a sledge hammer to swat a fly.

$result = explode('/', 'hyptertext language/ programming');


Anyway don’t forget to before.