bestand naar database...
ik heb een bestand, wat ik graag naar een database over wil zetten, alleen ik weet niet hoe ik het in een rij krijg.... kan iemand een voorbeeld scriptje maken???
dit is het bestand: http://stmichaelcollege.nl/weersmc/downld08.txt
grt, Robin
Welke database? Vrijwel iedere database heeft wel een functie om text-bestanden te importeren, bv. COPY in PostgreSQL of LOAD FILE in MySQL. Zie de handleiding van jouw database.
Uiteraard kun je ook met PHP de boel gaan uitlezen en met losse INSERT-queries de boel in de database wegschrijven. Mogelijkheden genoeg.
Edit: Moet LOAD zijn.
Gewijzigd op 01/01/1970 01:00:00 door Frank -
nu wil ik graag de laatste regel in een variabele hebben, en deze in de database proppen? hoe pas ik het script van Rens aan zodat hij de laatste regel pakt.
thanks! Het werkt :)
Code (php)
nu hoort ie de waarde 5 aan te geven, alleen doet ie dat niet? wat is er mis??
echo '<pre>'.print_r($cel, true).'</pre>';
(
[0] => 9-12-08 12:20
[1] => ---
[2] => ---
[3] => ---
[4] => ---
[5] => ---
[6] => 0.0
[7] => ---
[8] => 0.00
[9] => 0.0
[10] => ---
[11] => ---
[12] => ---
[13] => ---
[14] => --- 1012.4 0.00
[15] => 0.0
[16] => ---
[17] =>
[18] => ---
[19] => ---
[20] => ---
[21] => ---
[22] => ---
[23] => ---
[24] => ---
[25] => 22.2
[26] => 39
[27] => 7.6
[28] => 21.1
[29] => 0.00
[30] => 0
[31] => 1
[32] =>
[33] => 0.0
[34] => 5
)
hij pakt er een paar samen :P
mijn 'spatie' explode heeft geen zin, hoe kan ie splitten is er een manier om op iedere 'leegte' te splitten, maar alle spaties te verwijderen.
Gewijzigd op 01/01/1970 01:00:00 door Robin de Vries
Nou, $cel[36] bestaat dus niet, dat blijkt wel. Die waarde 5 waar jij het over hebt, zit in $cel[34]...
alleen deze filtrering is dus niet juist
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?php
$cel = explode(' ',$cellen);
?>
zie bovenstaand voorbeeld,
is er een andere manieer om ieder vakje apart te krijgen, want zoals je ziet
is $cel[14] gelijk aan 3 waarden..
$cel = explode(' ',$cellen);
?>
zie bovenstaand voorbeeld,
is er een andere manieer om ieder vakje apart te krijgen, want zoals je ziet
is $cel[14] gelijk aan 3 waarden..
Wat je zou kunnen doen is exploden op een enkele spatie en vervolgens de loze spaties die je in je array krijgt eruit knikkeren...
Code (php)
met als resultaat, deze zooi, zoiezo is het misschien niet het beste om explode uit te voeren op ' ' ...
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Array
(
[0] =>
[1] => 9-12-08
[2] =>
[3] => 12:20
[4] =>
[5] =>
[6] =>
[7] => ---
[8] =>
[9] =>
[10] =>
[11] => ---
[12] =>
[13] =>
[14] =>
[15] => ---
[16] =>
[17] =>
[18] => ---
[19] =>
[20] =>
[21] =>
[22] => ---
[23] =>
[24] =>
[25] => 0.0
[26] =>
[27] =>
[28] => ---
[29] =>
[30] =>
[31] => 0.00
[32] =>
[33] =>
[34] => 0.0
[35] =>
[36] =>
[37] => ---
[38] =>
[39] =>
[40] =>
[41] => ---
[42] =>
[43] =>
[44] =>
[45] => ---
[46] =>
[47] =>
[48] =>
[49] => ---
[50] =>
[51] =>
[52] =>
[53] => ---
[54] =>
[55] => 1012.4
[56] =>
[57] => 0.00
[58] =>
[59] =>
[60] => 0.0
[61] =>
[62] =>
[63] => ---
[64] =>
[65] =>
[66] =>
[67] =>
[68] =>
[69] => ---
[70] =>
[71] =>
[72] =>
[73] => ---
[74] =>
[75] =>
[76] =>
[77] =>
[78] => ---
[79] =>
[80] =>
[81] => ---
[82] =>
[83] =>
[84] => ---
[85] =>
[86] =>
[87] =>
[88] =>
[89] => ---
[90] =>
[91] =>
[92] =>
[93] =>
[94] => ---
[95] =>
[96] =>
[97] => 22.2
[98] =>
[99] =>
[100] =>
[101] => 39
[102] =>
[103] =>
[104] =>
[105] => 7.6
[106] =>
[107] =>
[108] => 21.1
[109] =>
[110] =>
[111] =>
[112] => 0.00
[113] =>
[114] =>
[115] =>
[116] =>
[117] => 0
[118] =>
[119] =>
[120] =>
[121] => 1
[122] =>
[123] =>
[124] =>
[125] =>
[126] =>
[127] => 0.0
[128] =>
[129] =>
[130] =>
[131] => 5
[132] =>
)
(
[0] =>
[1] => 9-12-08
[2] =>
[3] => 12:20
[4] =>
[5] =>
[6] =>
[7] => ---
[8] =>
[9] =>
[10] =>
[11] => ---
[12] =>
[13] =>
[14] =>
[15] => ---
[16] =>
[17] =>
[18] => ---
[19] =>
[20] =>
[21] =>
[22] => ---
[23] =>
[24] =>
[25] => 0.0
[26] =>
[27] =>
[28] => ---
[29] =>
[30] =>
[31] => 0.00
[32] =>
[33] =>
[34] => 0.0
[35] =>
[36] =>
[37] => ---
[38] =>
[39] =>
[40] =>
[41] => ---
[42] =>
[43] =>
[44] =>
[45] => ---
[46] =>
[47] =>
[48] =>
[49] => ---
[50] =>
[51] =>
[52] =>
[53] => ---
[54] =>
[55] => 1012.4
[56] =>
[57] => 0.00
[58] =>
[59] =>
[60] => 0.0
[61] =>
[62] =>
[63] => ---
[64] =>
[65] =>
[66] =>
[67] =>
[68] =>
[69] => ---
[70] =>
[71] =>
[72] =>
[73] => ---
[74] =>
[75] =>
[76] =>
[77] =>
[78] => ---
[79] =>
[80] =>
[81] => ---
[82] =>
[83] =>
[84] => ---
[85] =>
[86] =>
[87] =>
[88] =>
[89] => ---
[90] =>
[91] =>
[92] =>
[93] =>
[94] => ---
[95] =>
[96] =>
[97] => 22.2
[98] =>
[99] =>
[100] =>
[101] => 39
[102] =>
[103] =>
[104] =>
[105] => 7.6
[106] =>
[107] =>
[108] => 21.1
[109] =>
[110] =>
[111] =>
[112] => 0.00
[113] =>
[114] =>
[115] =>
[116] =>
[117] => 0
[118] =>
[119] =>
[120] =>
[121] => 1
[122] =>
[123] =>
[124] =>
[125] =>
[126] =>
[127] => 0.0
[128] =>
[129] =>
[130] =>
[131] => 5
[132] =>
)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Blanche schreef op 29.12.2008 16:36:
En daarom ook nooit empty() gebruiken! De waarde 0 is niet gelijk aan een lege waarde, ook al vindt empty() van wel. Dit is gewoon een bug in PHP, vergeet deze onzin en gooi deze functie uit je code.Argh, in het geval van 0 zal empty() ook true opleveren.
thanks blanche :)