Sorry to post again but now when I tried searching in google for a string on how figure out my issue this thread was the second listed choice. I'm really not able to find an answer on how to parse a space separated file that has variable spaces between the columns.
If excel is able to import the file successfully by selecting the space delimiter. And selecting " " as the delimiter doesnt work in PHP would this be a case where I have to use rtrim ?
I have no idea. Any suggestions ?
I even tried adding commas between the columns and using a comma as the delimiter in the code and it worked fine, so it must be an issue with the length of spaces between columns.
space delimiters
Moderator: General Moderators
Re: space delimiters
Im not sure what youre trying to do, but, you can read the file 1 line at a time and use preg_split() to split the line into columns in an array. the pattern "/[\s]+/" matches 1 or more spaces, and PREG_SPLIT_NO_EMPTY tells the function to not capture any empty strings.
hope that helps.
Code: Select all
preg_split("/[\s]+/", $file_content, -1, PREG_SPLIT_NO_EMPTY);hope that helps.