• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert a single column of values into a comma seperated list

My second question of the day, this can't be good!

I've got a csv with one column of values that i've uploaded and put into a variable.

The problem is that the values are seperated by a new line char or something (csv generated by MS Excel) and i need to make the list comma seperated.

Any ideas?!

Read file and replace new line char with comma?


Edit - I've tried "\n" as the delimiter but no joy.

the php function file gets the file content in an array so if you only have one column you can do
$lines = file($file);

Hmm that does not seem to work unfortunately.

What i've got thus far is (with your help from another post!):

$temp_csv = $_FILES['userfile']['tmp_name'];
$lines = file($temp_csv);

$jeff = implode(',',$lines);
echo $jeff;

So you get an array with one value if i understand you correct?

Yeah looks that way.

But you see in your csv file that the values are on different lines?

They are yes. Would it be helpful if i sent you the csv in question?

It's strange that you don't get an array with multiple values then, the problem with line breaks for the file function is only when it's a mac file. Maybe the fault is in the fact that the file isn't read. what do you get when you var_dump the $lines variable?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.