View Full Version : Having problems with split()

05-19-2008, 04: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!

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

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

05-19-2008, 07: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().

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