1

I have a CSV text file which contains serval entries of "books", each book is on one line (separator: line break), and each column is separated by a tabulation.

I'm reading the content the file with :

$books = file( "/path/to/file/mycsv.txt" , FILE_SKIP_EMPTY_LINES ); 

That way I can go throuhg each element of the "books" array and read my individual "book" data.

The problem is that each book has a "description" column, which also contains line breaks. On import, this messes up the data, as it creates a line break before the end of an item.

How can I prevent that ?

1

2 Answers 2

3

Does your file include quotes around the description column, because if it does I believe fgetcsv handles that situation.

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

Comments

1

You can use PHP RTRIM to trim the line breaks. or you can use a inbuilt feature of php fgetcsv to fetch the file.

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.