473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

explode by more than one separator

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
5 5044
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: the friendly display name | last post by:
Hello, In PHP there is the explode() function, it splits a string and returns an array consistent of the string parts. The string is split this way: $pizza =...
3
by: AceHigh | last post by:
Hello this is my first post, I want to disasemble some DLL's and add code to them, but I can only get Pelles C lib files to /EXPLODE with the POLIB.EXE extraction utility, however, I've managed to...
12
by: frizzle | last post by:
Hi there, i have a site with fake folders & files. htaccess rewrites everything to index.php?vars now in index.php i decide what file to include with a switch/case statement. to define where...
5
by: FFMG | last post by:
Hi, I need the php equivalent of explode in one of my app. I read a very big file and "explode" each line to fill a structure. The reading of the file, 19Mb, (I will also need to streamline...
0
by: k04jg02 | last post by:
Python has a nifty operator that will take a container and pass its elements as function parameters. In Python you can make a list like so: x = Then you can say: f(*x)
5
by: DJH | last post by:
I am trying to find the most efficient way to code a php explode in C++. What existing STL function may I use to separate this in to its parts where the delimiter is "||" ? example: ...
8
by: Jack | last post by:
I would like to Explode a string into an array that does not begin at 0 but I can't get it to work. For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo = 27 ... $MyInfo = 40...
5
by: sathyashrayan | last post by:
Dear group, The function to be used as follows: $links = "http://www.campaignindia.in/feature/analysis"; $tag1 = '<div class=feature-wrapper>'; $tag2 = '<h1><a href'; $tag3 = "</a>"; $op =...
8
by: vinpkl | last post by:
hi all i want to use explode url for shotening my urls i have a url like http://localhost/vineet/products.php?dealer_id=12&category_id=2 This is my navigation php code that has url...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.