I dont get it - preg_split patterns?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

I dont get it - preg_split patterns?

Post by Stryks »

Hi all,

I'm just wonderinf if someone could explain simply how the heck these things work.

I'm just trying to split a string on either a space or a comma, so I look up help on preg_split, but I cant make heads or tails of how the pattern relates to what it is supposed to find.

For example, it says that a pattern of '/[\s,]+/' is going to find 'commas or space characters which include " ".'

Whaaa?!?

Please ... can anyone help me understand this. I've come across it before in a few other functions and I just cant seem to find any info on what it all means.

Thanks
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Post by Stryks »

No help?

Even just an idea of where to get an explaination would be great.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

RegEx are the evil dragon in the realm of programming. But once you've got to know them a bit, they are extremely powerful (bit like a dragon).

There are plenty of tutorials about, just google for them - I remember I found one on phpbuilder.com quite useful.

Regarding the patterns itself - have a look at "Pattern Syntax" in the manual: http://uk.php.net/pcre.pattern.syntax

\s means any whitespace character, btw.
Post Reply