For instance, I have the following string:

table:column

I need to get "table" as the result of the php regular expression.

So, I need everything before the ":" symbol

After that regular expression is performed, I would also like to get everything after the ":" symbol, or "column" as well.

in this case I would use split.

$parts = split(":", "table:column");
$parts[0] //table
$parts[1] //column

in this case I would use split.

$parts = split(":", "table:column");
$parts[0] //table
$parts[1] //column

Whats the difference between that and explode?

Split and explode are the same thing, they are just two different names.

Hmm...Just googled it to double check and it said that split uses regex where as explode uses a string.

commented: True +1

That and explode is supposed to execute faster due to the lack of regex, although for what the OP wants, I doubt it will make much difference which is used.

Hmm...Just googled it to double check and it said that split uses regex where as explode uses a string.

If explode uses a string and split uses regex then what does preg_split use? What is the difference between split and preg_split? Just curious.

If explode uses a string and split uses regex then what does preg_split use? What is the difference between split and preg_split? Just curious.

"explode() takes a delimiter to split by ... split() takes a regular expression"
"documentation says that preg_split() is faster than split()"
http://blog.brianhartsock.com/2007/06/11/php-explode-vs-split/

"preg_split(), which uses a Perl-compatible regular expression syntax, is often a faster alternative to split(). If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine."
- http://uk3.php.net/split

Some speed stats: http://forums.codewalkers.com/php-coding-7/split-vs-preg-split-vs-explode-71423.html

So in answer to your question, preg_split uses regex like split. However, I don't know what the exact difference is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.