Page 1 of 1

Splitting strings in file to array

Posted: Wed Sep 05, 2007 3:38 pm
by tomcatf14
Hi,

I would like to split each strings to an array on a multiple lines file. The file should look like as below:-

------------------------------
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/ad0s2a 507630 190196 276824 41% /
devfs 1 1 0 100% /dev
/dev/ad0s2e 507630 20 467000 0% /tmp
/dev/ad0s2f 10154158 5673658 3668168 61% /usr
/dev/ad0s2d 6090094 4987298 615590 89% /var
------------------------------

How do i achieve that? I can use preg_split to split strings in a line to its array but haven't figure out on how to do it on multiple lines file. Each of the string above need to be assign to an array. Better still if there is something like coordinate to help. Eg. "array[1] = (row 2, col 2)"
Any help?

Posted: Wed Sep 05, 2007 5:28 pm
by RobertGonzalez
file() and explode() might help.

Posted: Thu Sep 06, 2007 1:05 am
by tomcatf14
Everah wrote:file() and explode() might help.
How i do use explode for non consistent white space across the file? Letz say like this:-

----------------------
Filesystem 1K-blocks Used Avail Capacity Mounted on

Posted: Thu Sep 06, 2007 6:00 am
by tomcatf14
Problem solved by using line count and loop array.