Hi everyone, I wrote a program in PHP that is reading a file in text format with "columns". The problem is with empty columns. The code I'm using is the following : foreach ($lines as $li => $line) { $c = preg_split("/[\s]+/", $line); ... } and then access to each column using $c[1], $c[2], etc. But when a column does not contains any value, this code returns the next column in place of the current one. For instance, if the file is the following one, with b for blank spaces and c for content: 1 ccc bbb c bbb cc bbb cc bbb ccc 2 ccc bbb c bbbbbbbbbb cc bbb ccc 3 ccc bbb c bbb cc bbb cc bbb ccc then, for the second line, the program reads only 4 columns instead of reading 5 columns with an empty one at the third position. And the value of the fourth columns is placed in $c[2], that is the third column value. Any help would be greatly appreciated, even sample code will be TIA, Maxpuckett,
How is the source file displaying columns? Just spacing out with a arbitrary number of spaces or tabs?
It's an arbitrary number of spaces between columns. In fact, I'm not able to figure out the exact number of spaces between two columns because some of columns are not equals... I mean, on one line, one colum could be 5 caracters, but 7 on the next line for the same column. But the columns are there, very well aligned on the right. Here is an example (the same as before), where bs are spaces and cs are content: 1 ccc bbb c bbb ccccc bbb cc bbb ccc 2 ccc bbb c bbbbbbbbbbbb cccc bbb ccc 3 ccc bbb c bbb cc bbb cc bbb ccc If you have a solution, I'll take it! Thanks in advance, Maxpuckett
If you figure out the structure you can open the file as a string and then replace the spaces with commas, this will make it easier to read I think.