2

I have a large DBF file that I would simply like to read like a .csv or .txt file by converting it into an array.

$file = file_get_contents('data.dbf');

Doing this just imports it as one huge blob of text. I tried

explode("\n\r", $file);

but that doesn't seem to work either as it treats it like one giant string with no line breaks. Excel btw reads it perfectly.

I don't have the dbase extension installed (not even sure if I can do that easily). Is there any other way I can read it properly line-by-line?

2
  • Try file() instead of file_get_contents(). This creates an array with each element being one line of the file. php.net/manual/en/function.file.php Commented Oct 6, 2016 at 17:48
  • I tried that. It still seems to treat it as one giant line. Commented Oct 6, 2016 at 18:53

1 Answer 1

1

It's better to use dBase PECL-extension for DBF-files, it allows you to read them properly and separate fields into array.
If you still want to use file() take into account a note from manual:

If PHP is not properly recognizing the line endings when reading files either on or created by a Macintosh computer, enabling the auto_detect_line_endings run-time configuration option may help resolve the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.