Forum Moderators: coopster
I have tab delimited file that is produced from a specific software, and i should work on it without re-saving it! I want to import it and save it to DB.. my problem is just in reading it!
Everything works fine when I open it by excel and re-save it as tab delimited (But I should not do so).
The problem in the original file is that I can't detect its new line and neither can PHP functions file() nor fgetcsv().
But if I opened it by excel, it opens correctly, each field on its own and each line on its own, so there must be newline sign there but I cant find it at all..
I am trying to echo the position of any newline value, i tried:
$handle = fopen($file, "r");
$data_rows = fgetcsv($handle, 0, "\t");
echo strpos($data_rows[0],"\n");exit;
\n
\r\n
<br>
<br />
So what could be the newline value?
as opposed to explode did you try using functions that grab line by line from a file to see if they may be able to do it
you could try
file_get_contents
fgets
fgetcsv
or even just fread but I doubt that will work
the other thing is that it may not be a newline or carriage return at all, it could be some other char all together that excel seems to know
you could also look at the software that is producing it and see if there are settings for file type.
I tried now to copy the small square char that appears in the text editor and paste it in dreamweaver.. so it pasted a new line as if i hit enter!
So we agree that there is newline sign out there but not clear what is it!
loop it
add value to array
when you get to the number of cols start the next element
take a look in the comments on this page
[php.net...]
search the page for 'newline', might give some insight
for each value between tabs you could assign it to a new element
though I guess you would still need to figure out the strange char as there would be no tab there
no clue, you need to find a way to identify that char, the link above may help