473,385 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

file_get_contents() not showing new lines

25
I am trying to parse certain excel sheets. I converted them to csv files to strip out any excess formatting. To parse these files, my system is dependant on new lines ("/n"). I use this code to get the data from the uploaded csv file:

Expand|Select|Wrap|Line Numbers
  1. $data = file_get_contents($_FILES["file"]["tmp_name"], FILE_USE_INCLUDE_PATH);
The problem is that any of the new lines in the csv show up as single spaces in $data. I was wondering if there is a way to preserve the new lines in $data.
Jun 20 '10 #1

✓ answered by dgourd

I am uploading the data through a form. I found by using this:
Expand|Select|Wrap|Line Numbers
  1. $data = file($_FILES["file"]["tmp_name"], FILE_USE_INCLUDE_PATH | FILE_IGNORE_NEW_LINES);
It returns the data as an array with each new line as a separate array entry. Thanks for your help though.

3 7995
Atli
5,058 Expert 4TB
How are you viewing the data? Note that HTML does not respect white-space chars, so new-lines and multiple spaces are ignored. Try wrapping them into a <pre> block.

Also, you may want to check out the fgetcsv function. It reads in a line from a CSV file and returns the values in it as an array.
Jun 21 '10 #2
dgourd
25
I am uploading the data through a form. I found by using this:
Expand|Select|Wrap|Line Numbers
  1. $data = file($_FILES["file"]["tmp_name"], FILE_USE_INCLUDE_PATH | FILE_IGNORE_NEW_LINES);
It returns the data as an array with each new line as a separate array entry. Thanks for your help though.
Jun 21 '10 #3
HaLo2FrEeEk
404 256MB
Darn, you beat me to it. I was just about to suggest file(), it's helped me quite a few times.
Jun 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Daniel Hill | last post by:
OK, I have very, VERY basic background knowledge of VB6 and have now upgraded to VB.NET and now I'm struggling to bring up the forms I want. What I am looking to do is to have a click a command...
26
by: Shannon Jacobs | last post by:
Sorry to ask what is surely a trivial question. Also sorry that I don't have my current code version on hand, but... Anyway, must be some problem with trying to do the negative. It seems like I get...
1
by: Rich | last post by:
Hello, I am trying to draw a graph on a form. I can draw the box using drawline, and bars inside the box using drawrectangle, but when I try to draw a line inside the box the inner lines are...
4
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. ...
1
by: Benny Raymond | last post by:
I have lines of data coming from a server being written to a RichTextBox... The problem is that if I let this program run for a long period of time there are hundreds of lines of text showing up in...
0
by: James Allen Bressem | last post by:
Do drag n drop in VB.Net in ten lines of code - (too easy) I was searching through the MSDN documentation trying to figure out how to do drag n drop and I found a sample program. The sample...
3
by: HDB | last post by:
Ok. I have a windows form with a textbox for displaying certain messages. Multiline=true and wordwrap=true. I want to know the amount of the lines currently showing. That should not be any...
1
by: Grimm | last post by:
I am developing an internalk inteface that integrates alot of seperate tools into one interface. The current version uses one Iframe inside a div layer for positioning. Currently the seperate web...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
5
by: huud | last post by:
How can I code a loop of a text file showing it's first 20 lines and after pressing enter it shows the next 20 lines and so on?
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.