Welcome Guest, Not a member yet? Register   Sign In
Convert a single column of values into a comma seperated list
#1

[eluser]johnwbaxter[/eluser]
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?!
#2

[eluser]Unknown[/eluser]
Read file and replace new line char with comma?
#3

[eluser]johnwbaxter[/eluser]
Yep!

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

[eluser]xwero[/eluser]
the php function file gets the file content in an array so if you only have one column you can do
Code:
$lines = file($file);
implode(',',$lines);
#5

[eluser]johnwbaxter[/eluser]
Hmm that does not seem to work unfortunately.

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

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

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

[eluser]xwero[/eluser]
So you get an array with one value if i understand you correct?
#7

[eluser]johnwbaxter[/eluser]
Yeah looks that way.
#8

[eluser]xwero[/eluser]
But you see in your csv file that the values are on different lines?
#9

[eluser]johnwbaxter[/eluser]
They are yes. Would it be helpful if i sent you the csv in question?
#10

[eluser]xwero[/eluser]
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?




Theme © iAndrew 2016 - Forum software by © MyBB