Jump to content

Exploded


jaymc

Recommended Posts

I have the following data to work with

 

     Jamie McCoy         08:29:36         19           0           1            401       9.0         399.6                         1             14         60         0         1

 

It will always be in that format with each set of information in the above order, but may contain different names or numbers..

 

What I need to do is put each bit of information in an array, I usually use explode but as you can theres no much to explode by apart from the large white spaces between each bit of data

 

However, sometimes the white spaces may be a little large, for example, 5 white chars instead of 8 white chars (depending on the amount of space there name takes up, See Example

 

     Jamie McCoy         08:29:36         19           0           1            401       9.0         399.6                         1             14         60         0         1
     Jay George          08:28:12         1            0           0            172      19.7         172.0                         0             6          94         0         0
    John Burquest        08:26:57         24           0           1            413       8.7         374.5                        35             37         30         3         1

 

So, how can I basically get it so I can have

 

$s[0] = Jamie McCoy

$s[1] = 08:29:36

$s[2] = 19

etc...

 

Is explode the only really way to split the data up?

Link to comment
Share on other sites

what about

split or spliti

 

split

array split ( string $pattern, string $string [, int $limit] )

Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the case-sensitive regular expression pattern. If limit  is set, the returned array will contain a maximum of limit elements with the last element containing the whole rest of string. If an error occurs, split() returns FALSE.

 

 

spliti

array spliti ( string $pattern, string $string [, int $limit] )

 

This function is identical to split() except that this ignores case distinction when matching alphabetic characters.

 

 

EDIT:

preg_split — Split string by a regular expression

Description

array preg_split ( string $pattern, string $subject [, int $limit [, int $flags]] )

Split the given string by a regular expression.

 

 

If you say the minimum spaces to be classed as a delimitor is 3 spaces, then replace all 4 spaces with 3 until no more 4 spaces exist, then use "  " (3xspaces) as a delimitor

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.