|
|
|
สอบถามเรื่องการตัด array ใน php จากการ import file csv ครับ |
|
|
|
|
|
|
|
จากไฟล์ CSV
Quarter III, 2011 - 2012 Academic Year Schedule,,,,,,,,,
0 - 0 ,,,,,,,,,,
Subject,Prerequisite(s),(Sec),,Day/Time,ID Code,Instructor,Room,Final,,
,,(Cap.),,,,,,,,
EGCI 100 Introduction to computer engineering 1(0-2),,1,M.,12:00 - 13:50,I01092,Suratose TRITILANUNT,,20/8/2012,,
,,-30,.,,,,,12:00-13:50,,
EGCI 111 Computer Programming 4(3-2),,1,M.,14:00 - 15:50,I01207,Mingmanas SIVARAKSA,,16/8/2012,,
,,-30,Th.,09:00 - 11:50,,,,14:00-15:50,,
EGCI 201 Discrete Mathematics 4(4-0),,1,Tu.,14:00 - 15:50,I01110,Pisit PHOKHARATKUL,,14/8/2012,,
,,-30,F.,10:00 - 11:50,,,,14:00-15:50,,
EGCI 202 Numerical Methods and Applications 4(4-0),,1,W.,14:00 - 15:50,I01093,Tatcha CHULAJATA,,15/8/2012,,
,,-30,F.,14:00 - 15:50,,,,14:00-15:50,,
EGCI 213 Programming Paradigms 4(4-0),,1,M.,14:00 - 15:50,I01111,Rangsipan MARUKATAT,,16/8/2012,,
,,-30,Th.,14:00 - 15:50,,,,14:00-15:50,,
EGCI 232 Engineering Electronics 4(3-2),,1,Tu.,10:00 - 11:50,I01190,Somnida BHATRANAND,,16/8/2012,,
,,-30,Th.,10:00 - 12:50,,,,10:00-11:50,,
ผมใช้ code
Code (PHP)
$handle = fopen("cc.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo "<pre>";
print_r($data);
}
แล้วผลคือ
Array
(
[0] => Quarter III
[1] => 2011 - 2012 Academic Year Schedule
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] => 0 - 0
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] => Subject
[21] => Prerequisite(s)
[22] => (Sec)
[23] =>
[24] => Day/Time
[25] => ID Code
[26] => Instructor
[27] => Room
[28] => Final
[29] =>
[30] =>
[31] =>
[32] => (Cap.)
[33] =>
[34] =>
[35] =>
[36] =>
[37] =>
[38] =>
[39] =>
[40] => EGCI 100 Introduction to computer engineering 1(0-2)
[41] =>
[42] => 1
[43] => M.
[44] => 12:00 - 13:50
[45] => I01092
[46] => Suratose TRITILANUNT
[47] =>
[48] => 20/8/2012
[49] =>
[50] =>
[51] =>
[52] => -30
[53] => .
[54] =>
[55] =>
[56] =>
[57] =>
[58] => 12:00-13:50
[59] =>
[60] => EGCI 111 Computer Programming 4(3-2)
[61] =>
[62] => 1
[63] => M.
[64] => 14:00 - 15:50
[65] => I01207
[66] => Mingmanas SIVARAKSA
[67] =>
[68] => 16/8/2012
[69] =>
[70] =>
[71] =>
[72] => -30
[73] => Th.
[74] => 09:00 - 11:50
[75] =>
[76] =>
[77] =>
[78] => 14:00-15:50
[79] =>
[80] => EGCI 201 Discrete Mathematics 4(4-0)
[81] =>
[82] => 1
[83] => Tu.
[84] => 14:00 - 15:50
[85] => I01110
[86] => Pisit PHOKHARATKUL
[87] =>
[88] => 14/8/2012
[89] =>
[90] =>
[91] =>
[92] => -30
[93] => F.
[94] => 10:00 - 11:50
[95] =>
[96] =>
[97] =>
[98] => 14:00-15:50
[99] =>
[100] => EGCI 202 Numerical Methods and Applications 4(4-0)
[101] =>
[102] => 1
[103] => W.
[104] => 14:00 - 15:50
[105] => I01093
[106] => Tatcha CHULAJATA
[107] =>
[108] => 15/8/2012
[109] =>
[110] =>
[111] =>
[112] => -30
[113] => F.
[114] => 14:00 - 15:50
[115] =>
[116] =>
[117] =>
[118] => 14:00-15:50
[119] =>
[120] => EGCI 213 Programming Paradigms 4(4-0)
[121] =>
[122] => 1
[123] => M.
[124] => 14:00 - 15:50
[125] => I01111
[126] => Rangsipan MARUKAT
)
Array
(
[0] => AT
[1] =>
[2] => 16/8/2012
[3] =>
[4] =>
[5] =>
[6] => -30
[7] => Th.
[8] => 14:00 - 15:50
[9] =>
[10] =>
[11] =>
[12] => 14:00-15:50
[13] =>
[14] => EGCI 232 Engineering Electronics 4(3-2)
[15] =>
[16] => 1
[17] => Tu.
[18] => 10:00 - 11:50
[19] => I01190
[20] => Somnida BHATRANAND
[21] =>
[22] => 16/8/2012
[23] =>
[24] =>
[25] =>
[26] => -30
[27] => Th.
[28] => 10:00 - 12:50
[29] =>
[30] =>
[31] =>
[32] => 10:00-11:50
[33] =>
)
แต่ผมอยากให้มันขึ้น array ใหม่ทุกๆวิชา ไม่ใช่ วิ่งยาวแบบนี้อะครับ เป็น
Array(
[0] => EGCI 111 Computer Programming 4(3-2)
[1] =>
[2] => 1
[3] => M.
[4] => 14:00 - 15:50
[5] => I01207
[6] => Mingmanas SIVARAKSA
[7] =>
[8] => 16/8/2012
[9] =>
[10] =>
[11] =>
[12] => -30
[13] => Th.
[14] => 09:00 - 11:50
[15] =>
[16] =>
[17] =>
[18] => 14:00-15:50
[19] =>
)
แล้ก็ตัดใหม่
Array(
[0] => EGCI 201 Discrete Mathematics 4(4-0)
[1] =>
[2] => 1
[3] => Tu.
[4] => 14:00 - 15:50
[5] => I01110
[6] => Pisit PHOKHARATKUL
[7] =>
[8] => 14/8/2012
[9] =>
[10] =>
[11] =>
[12] => -30
[13] => F.
[14] => 10:00 - 11:50
[15] =>
[16] =>
[17] =>
[18] => 14:00-15:50
[19] =>
)
ผมต้องทำยังไงครับ รบกวนด้วยครับมือใหม่ครับ ขอบคุณครับ
Tag : PHP, Excel (Excel.Application)
|
|
|
|
|
|
Date :
2012-06-29 14:04:17 |
By :
Gojito |
View :
1229 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
น่าจะต้องใช้พวก Split แทนน่ะครับ ส่วนจะตัดจากตรงไหนก็ดูที่ pattern ที่ต้องการ
|
|
|
|
|
Date :
2012-06-30 07:48:29 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|