Alle data van ftp_rawlist in een array stoppen.
Ik dacht zo ongeveer:
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
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
Array
(
[0] => Array
(
[name] => nl
[isdir] => true
[permissions] => drwxr-xr-x
[owner] => username_robin
[group] => username_robin
[size] => 4096
[lastedit] => 1280257137
)
[0] => Array
(
[name] => en
[isdir] => true
[permissions] => drwxr-xr-x
[owner] => username_robin
[group] => username_robin
[size] => 4096
[lastedit] => 1280255369
)
[0] => Array
(
[name] => header.php
[isdir] => false
[permissions] => drwxr-xr-x
[owner] => username_robin
[group] => username_robin
[size] => 8419
[lastedit] => 1280257327
)
)
(
[0] => Array
(
[name] => nl
[isdir] => true
[permissions] => drwxr-xr-x
[owner] => username_robin
[group] => username_robin
[size] => 4096
[lastedit] => 1280257137
)
[0] => Array
(
[name] => en
[isdir] => true
[permissions] => drwxr-xr-x
[owner] => username_robin
[group] => username_robin
[size] => 4096
[lastedit] => 1280255369
)
[0] => Array
(
[name] => header.php
[isdir] => false
[permissions] => drwxr-xr-x
[owner] => username_robin
[group] => username_robin
[size] => 8419
[lastedit] => 1280257327
)
)
Dit is mijn beignetje:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<pre>
<?php
$conn_id = ftp_connect($server);
$login_result = ftp_login($conn_id, $username, $password);
$buff = ftp_rawlist($conn_id, $dir);
ftp_close($conn_id);
//print_r($files);
?>
</pre>
<?php
$conn_id = ftp_connect($server);
$login_result = ftp_login($conn_id, $username, $password);
$buff = ftp_rawlist($conn_id, $dir);
ftp_close($conn_id);
//print_r($files);
?>
</pre>
Gewijzigd op 28/07/2010 12:34:16 door Robin van der Vliet
Aan de hand hiervan: drwxr-x--- 3 vincent vincent 4096 Jul 12 12:16 public_ftp
Maak ik deze RE:
/^(.[rstwxX\-]{9})\s+(\d+)\s+([0-9a-zA-Z]+)\s+([0-9a-zA-Z]+)\s+(\d+)\s+(.+?)\s+(.+)$/
Maar hoe moet ik die dan toepassen?
Gewijzigd op 28/07/2010 12:34:07 door Robin van der Vliet
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<pre>
<?php
$conn_id = ftp_connect($server);
$login_result = ftp_login($conn_id, $username, $password);
$buff = ftp_rawlist($conn_id, $directory);
ftp_close($conn_id);
$i = 0;
foreach ($buff as $value)
{
preg_match('/^(.[rstwxX\-]{9})\s+(\d+)\s+([0-9a-zA-Z]+)\s+([0-9a-zA-Z]+)\s+(\d+)\s+(.+?)\s+(.+)$/', $buff[$i], $matches[$i]);
$i++;
}
print_r($matches);
?>
</pre>
<?php
$conn_id = ftp_connect($server);
$login_result = ftp_login($conn_id, $username, $password);
$buff = ftp_rawlist($conn_id, $directory);
ftp_close($conn_id);
$i = 0;
foreach ($buff as $value)
{
preg_match('/^(.[rstwxX\-]{9})\s+(\d+)\s+([0-9a-zA-Z]+)\s+([0-9a-zA-Z]+)\s+(\d+)\s+(.+?)\s+(.+)$/', $buff[$i], $matches[$i]);
$i++;
}
print_r($matches);
?>
</pre>
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
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
Array
(
[0] => Array
(
[0] => drwxr-xr-x 23 ftp ftp 4096 Jul 28 12:04 .
[1] => drwxr-xr-x
[2] => 23
[3] => ftp
[4] => ftp
[5] => 4096
[6] => Jul
[7] => 28 12:04 .
)
[1] => Array
(
[0] => drwx--x--x 8 ftp ftp 4096 Jul 17 00:56 ..
[1] => drwx--x--x
[2] => 8
[3] => ftp
[4] => ftp
[5] => 4096
[6] => Jul
[7] => 17 00:56 ..
)
[2] => Array
(
[0] => -rw-r--r-- 1 ftp ftp 353 Jul 27 07:43 .htaccess
[1] => -rw-r--r--
[2] => 1
[3] => ftp
[4] => ftp
[5] => 353
[6] => Jul
[7] => 27 07:43 .htaccess
)
.........
)
(
[0] => Array
(
[0] => drwxr-xr-x 23 ftp ftp 4096 Jul 28 12:04 .
[1] => drwxr-xr-x
[2] => 23
[3] => ftp
[4] => ftp
[5] => 4096
[6] => Jul
[7] => 28 12:04 .
)
[1] => Array
(
[0] => drwx--x--x 8 ftp ftp 4096 Jul 17 00:56 ..
[1] => drwx--x--x
[2] => 8
[3] => ftp
[4] => ftp
[5] => 4096
[6] => Jul
[7] => 17 00:56 ..
)
[2] => Array
(
[0] => -rw-r--r-- 1 ftp ftp 353 Jul 27 07:43 .htaccess
[1] => -rw-r--r--
[2] => 1
[3] => ftp
[4] => ftp
[5] => 353
[6] => Jul
[7] => 27 07:43 .htaccess
)
.........
)
Er zitten nog enkele foutjes in zoals:
De d word nog meegerekent als permission terwijl dat eigenlijk is of het een map is of niet.
En hij zet de dag, uur en minuut en naam in dezelfde variable en ik wilde graag als het kan dat er dan een variable is met een timestamp en een variable met de naam.
Gewijzigd op 30/07/2010 11:03:17 door Robin van der Vliet
Nu is het jouw beurt om je verder te verdiepen in hoe RegEx werken, hier is aan jou een mooie duw in de goede richting gegeven. Laat ons maar horen wat je er van gemaakt hebt!