...

View Full Version : Having problems with split()



cyphix
05-19-2008, 03:03 PM
Hey guys.... I'm trying to use split() to split some data into an array but it's not working.... it keeps being returned as one line. :(

Here is my code..



foreach ($data as $line) {
$line = trim($line);
$parts = split('~\s+~', $line, 2);
// ...
}


Here is some example data that I am using..



PAAB 12345
PAAD 12345
PAAI 12345
PAAJ 12345
PAAM 12345
PABD 12345
PABG 12345
PACB 12345
PACM 12345


Thanks for any help!

abduraooft
05-19-2008, 03:47 PM
What's the type of your variable $data? 2D array?

cyphix
05-19-2008, 04:52 PM
Sorry....... the text I provided is retrieved by using file().

kbluhm
05-19-2008, 06:34 PM
Split doesn't use delimiters (which is what I am going to assume the ~ characters are).

Leave your code as is, except replace split() with preg_split().

cyphix
05-20-2008, 12:58 PM
Thanks for that! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum