By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

preg_split not working

P: 72
Can anyone help me with the pattern in a regular expression?

I want to split a string into words delimited by ".", "-" and "/".

eg.
Expand|Select|Wrap|Line Numbers
  1. $words = preg_split("/[-.]+/", "test-lang.prog/good");
  2.  
I expect 4 words in the array "test","lang","prog" and "good".

I don't know how to put the "/" in the pattern.

"/[/-.]+/"
"/[\/-.]+/" are obviously not right

Also, why printf($words[1]) displays ok but printf($words) shows a blank?


Thanks for any help
Dec 27 '11 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
what about preg_split("#[-./]#", "test-lang.prog/good"); ?

"/[\/-.]+/" are obviously not right
- has a speacial meaning inside a class (between … and …), unless it is the first character (where between-and doesn’t make sense)
Dec 27 '11 #2

P: 72
That worked. So simple!

Thanks Dormilich
Dec 27 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.