I have to write a script that will read a multiple delimited file (one or more tabs, one or more space or a mix of space and tab). How to do this in PHP.
@temp_user123Jul 03.2007 — #Depends. Is the file considered a [B]CSV [/B]file? ...i.e., can it be opened correctly in [B]Excel[/B]? If so, then [B]fgetcsv()[/B] may work just fine for you. If not, you may have to use [B]fread()[/B] and parse it yourself.
@kl1980authorJul 03.2007 — #NO it is just a text file. I have attached a sample file below. I have to read that file and store each field (ID, Text, RGB.....) in an array.
How do I do that. I have read a file that is either tab delimited or space delimited, but not a multiple delimited file.
@bluestarsJul 04.2007 — #Can there be spaces in that string?
If not, you could just read to an array, then replace all TABs with spaces (or vice-versa), then explode on a space.
If there are, you'd have to make up a regexp that matches all spaces NOT inside "", then replace those with tabs or semicolons or something, then explode it.
@temp_user123Jul 04.2007 — #I downloaded the file. There are both multiple spaces and multiple tabs between some data elements. Like I said, [B]preg_match()[/B] will, in a single step, automatically give you an array of the data elements -- all stripped of all such white space characters. Actually, now that I think about it, you'd need to use [B]preg_match_all()[/B] instead. ?