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

explode by more than one separator

P: n/a
Hi

Is it possible to explode a string into an array using more than one
separator? I have database records that contain several values, mostly split
by semi-colons but some older records are split by comma.

It's obviously no hassle if I have to explode twice but it'd be nice if I
could do it with one line...

cheers, Rob
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Rob Gudgeon:
Hi

Is it possible to explode a string into an array using more than one
separator? I have database records that contain several values, mostly
split by semi-colons but some older records are split by comma.


Yeah. preg_split()

André Nęss
Jul 17 '05 #2

P: n/a
Rob Gudgeon wrote:

Is it possible to explode a string into an array using more than one
separator? I have database records that contain several values,
mostly split by semi-colons but some older records are split by comma.

It's obviously no hassle if I have to explode twice but it'd be nice
if I could do it with one line...


You use "split" instead of "explode" for that (with regular
expressions).

The following is a PHP.net example splitting on "/", ".", and "-"
(unfortunately only in German in my browser, so here's some
translation):

<?
$myDate = "2003/12/12";
list ($myMonth, $myDay, $myYear) = split ('[/.-]', $myDate);
echo "Month: $myMonth; Day: $myDay; Year: $myYear<br />\n";
?>
Jul 17 '05 #3

P: n/a
Philipp Lenssen wrote:

The following is a PHP.net example splitting on "/", ".", and "-"
(unfortunately only in German in my browser, so here's some
translation):


OK, got it to switch to English:
http://de2.php.net/manual/en/function.split.php

<?php
// Delimiters may be slash, dot, or hyphen
$date = "04/30/1973";
list($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br />\n";
?>
Jul 17 '05 #4

P: n/a
all the solution before will work but whould it be better to replace colons
by semi-colons in your database, since they will all have the same syntax ?
Just an other solution.

Savut

"Rob Gudgeon" <ro***********@SPAMTRAP.bt.com> wrote in message
news:bq**********@visp.bt.co.uk...
Hi

Is it possible to explode a string into an array using more than one
separator? I have database records that contain several values, mostly split by semi-colons but some older records are split by comma.

It's obviously no hassle if I have to explode twice but it'd be nice if I
could do it with one line...

cheers, Rob

Jul 17 '05 #5

P: n/a
"André Nęss" <an*********************@ifi.uio.no> wrote in message
news:bq**********@maud.ifi.uio.no...
Rob Gudgeon:
Hi

Is it possible to explode a string into an array using more than one
separator? I have database records that contain several values, mostly
split by semi-colons but some older records are split by comma.


Yeah. preg_split()

André Nęss


Thanks for all your replies - preg_split was the one I've gone for

cheers, Rob
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.