Bluehost.com Web Hosting $6.95

Splitting a string into arrays within an array but only one delimiter?

This is a discussion on Splitting a string into arrays within an array but only one delimiter? within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm trying to split a string into an separate arrays but the data is only delimited by a ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-10-2008
spreadbetting@gmail.com
 
Posts: n/a
Default Splitting a string into arrays within an array but only one delimiter?

Hi,

I'm trying to split a string into an separate arrays but the data is
only delimited by a comma. The actual data is one long string but the
info is in a regular format and repeats after every five ~'s .

i.e the data may be returned as

1.01~11844.69~0.0~0.0~2.0~1.02~117.3~0.0~0.0~0.0~1 .03~66.82~0.0~0.0~0.0~1.04~300.0~0.0~0.0~0.0~

I guess I just have to loop through every five ~'s but unsure of the
best way using php , with C# I guess I could use length but haven't
too much of a clue using php. At the moment I'm even considering a
dirty fix using preg_replace to change the delimiter every 5 ~'s but
there must be a more correct way

Thanks

Reply With Quote
  #2 (permalink)  
Old 06-12-2008
mrclay
 
Posts: n/a
Default Re: Splitting a string into arrays within an array but only onedelimiter ?

On Jun 10, 5:11 am, spreadbett...@gmail.com wrote:
> I'm trying to split a string into an separate arrays but the data is
> only delimited by a comma. The actual data is one long string but the
> info is in a regular format and repeats after every five ~'s .
> 1.01~11844.69~0.0~0.0~2.0~1.02~117.3~0.0~0.0~0.0~1 .03~66.82~0.0~0.0~0.0~1.04~300.0~0.0~0.0~0.0~


It sounds vaguely like you want something like:

$setsOfFive = array_chunk(explode('~', $line), 5);

....but you need to be more clear of what you mean by "the data" and
"the actual data". Give an example of input and desired output.

Steve
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 04:41 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0