Destramic Posted January 30, 2015 Share Posted January 30, 2015 first of all...its good to see the site back . my question guys is i'm wondering is there a way of getting the column number when reading a .cvs file? ie. a, b, c, d, aa, ab etc? $row = 1; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { //echo $data[$c] . "<br />\n"; } } fclose($handle); } now $num counts the columns...but i want to convert that into a alphabetical column...is there a easy solution? thanks guys Link to comment https://forums.phpfreaks.com/topic/294278-cvs-files/ Share on other sites More sharing options...
CroNiX Posted January 30, 2015 Share Posted January 30, 2015 Something like this: https://www.daniweb.com/web-development/php/threads/364699/php-converting-numbers-to-letters or http://www.tiny-threads.com/blog/2013/11/12/php-convert-number-excel-column-letter-2/ Link to comment https://forums.phpfreaks.com/topic/294278-cvs-files/#findComment-1504399 Share on other sites More sharing options...
Barand Posted January 30, 2015 Share Posted January 30, 2015 for ($c=0, $a='a'; $c < $num; $c++, $a++) { //echo "($a) " . $data[$c] . "<br />\n"; } Link to comment https://forums.phpfreaks.com/topic/294278-cvs-files/#findComment-1504402 Share on other sites More sharing options...
Destramic Posted January 31, 2015 Author Share Posted January 31, 2015 thanks for your posts guys...cronix that was just what i was after ...cheers Link to comment https://forums.phpfreaks.com/topic/294278-cvs-files/#findComment-1504425 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.