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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |