Difference between explode and split

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
oQEDo
Forum Commoner
Posts: 43
Joined: Thu Feb 20, 2003 11:08 am
Location: UK

Difference between explode and split

Post by oQEDo »

Im not too sure of how the functions split and explode work. Their explainations are pretty similar in the notes however the differences are:

Split
....splitting it on boundaries formed by the string separator
Explode
.....splitting it on boundaries formed by the regular expression pattern
Can someone please give me a simple explaination of what this actually means :?:

Thanks
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

Split uses Regular Expressions, Explode uses pure strings.. If you don't need regular expression power, use Explode, it's much faster/less resource-using.. (Just as it says in the manual)
User avatar
oQEDo
Forum Commoner
Posts: 43
Joined: Thu Feb 20, 2003 11:08 am
Location: UK

Regular Expression

Post by oQEDo »

Thanks Stoker however for my next question.....
What is a regular expression?
Could you give me an example of a regular expression and an example of something which is not a regular expression? I'm finding it tricky to get my head round this.

Thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

A regular expression is used to match a pattern, so for example you might want to search for all instances of e-mail addresses - they're each going to be different (me@mydomain.com, you@yourdomain.net) but they follow a similar pattern. For this you would use a regular expression to match that pattern.

If, however, you wanted to find all instances of me@mydomain.com, then you wouldn't use a regular expression because it's the same string that you're searching for each time.

Found this in Google:
http://www.regularexpression.info/

Mac
User avatar
oQEDo
Forum Commoner
Posts: 43
Joined: Thu Feb 20, 2003 11:08 am
Location: UK

Post by oQEDo »

Thanks twigletmac,

Thats exactly what I was looking for.
Post Reply