Re: [PHP] Making an array from delimited data

[email protected] ("Nathan Nobbe")
Newsgroups php.general
Message-ID <[email protected]>
On Mon, Apr 28, 2008 at 1:44 PM, Joe Harman <[email protected]> wrote:

> I have some data that I pull from a database that is in the following
> format:
>
> -------------------------------------------------------------
> Gauge Style: Auto Meter Pro-Comp
> Tachometer Usage: Standard
> Gauge Series: Analog
> Gauge Range: 0-11,000 rpm
> Gauge Diameter (in): 5 in.
> Gauge Diameter (mm): 127.00mm
> Sweep: Full sweep
> -------------------------------------------------------------
>
> I want the array to end up like this
> --------------------------------------------------------------------------
> $data['Gauge Style'] = Auto Meter Pro-Comp
> $data['Tachometer Usage'] = Standard
> $data['Gauge Series'] = 0-11,000 rpm
>
> I know I can use explode on on set of data... but up do you do it line by
> line?


foreach(explode("\n", trim($dbData)) as $curLine) {
  $parsedLine = explode(':', $curline)) {
    $data[$parsedLine[0]] = $parsedLine[1];
  }
}

-nathan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.