oui pour les mots à rechercher tu peux faire comme j'ai fait au post n°5
Version imprimable
oui pour les mots à rechercher tu peux faire comme j'ai fait au post n°5
merci pour votre réponse
j'ai tester la fonction que tu ma donné
il n'affiche rien (une page blanche) par contre la page violence.php contient le mot violence alors la fonction n'affiche pas le path /test/violence.phpCode:
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 <?php $words = array( 'violence', 'terrorisme', '-18ans', ); $files = array( 'test/violence.php', 'test/terorisme.php', 'test/test2.php' ); $found = explicitContent($words, $files); function explicitContent( array $words,array $files) { $intersect = array(); foreach($files as $path) { $file = file_get_contents($path, FILE_USE_INCLUDE_PATH); foreach($words as $word) { if (stripos($file, $word) !== false) { $intersect[$word][] = $path; echo $intersect[$word][] = $path; } } } return $intersect; } echo $intersect[$word][] = $path; ?>
merci d'avance
Tu es débutant en PHP, fallait le dire de suite :
Réessaye avec ceci et dis-moi si tu récupères quelque chose :
Code:
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 <?php function explicitContent(array $words, array $files) { $intersect = array(); foreach($files as $path) { $file = file_get_contents($path); foreach($words as $word) { if (stripos($file, $word) !== false) { $intersect[$word][] = $path; } } } return $intersect; } $words = array( 'violence', 'terrorisme', '-18ans', ); $files = array( 'test/violence.php', 'test/terorisme.php', 'test/test2.php' ); $found = explicitContent($words, $files); print_r($found); ?>
Le résultat te montre que tu obtiens ce que tu cherches :
Code:
1
2
3 violence -> trouvé dans test/violence.php et test/test.php terrorisme -> trouvé dans test/t.php -18ans -> trouvé dans test/t.php
oui cette résultat merci
j'ai ajouter à mon script
et jai' commenterCode:
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 <html> <body> <?php function ScanDirectory($directory) { $files = array(); $iter = new RecursiveDirectoryIterator($directory); foreach(new RecursiveIteratorIterator($iter) as $file) { $files[] = $file->getPathname(); } return $files; } $files = ScanDirectory($directory); ?> <?php @session_start(); if(empty($_POST)){ ?> <form method="post" action=""> Veuillez entrer le nom du dossier : <input type="text" name="path" value=""> <br><br> <input type="submit" name="bouton" value="Envoyer"> </form> <?php } else{ ScanDirectory($_POST['path']); } ?> </body> </html>
le tableau files
lorsque je lance mon jai une page blance scriptCode:
1
2
3
4
5
6 /* $files = array( 'test/violence.php', 'test/terorisme.php', 'test/test2.php' );*/
merci d'avance
Bah vu ton script c'est plutôt normal.
Il faut que tu tes plonge d'abord dans la théorie parce que tu sembles ramer sévère. Sans les connaissances de base, point de salut.
J'ai repris ton script sans rien tester alors je croise les doigts.
A bidouiller jusqu'à arriver au résultat voulu.Code:
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 <?php session_start(); function scanDirectory($directory) { $files = array(); $iter = new RecursiveDirectoryIterator($directory); foreach(new RecursiveIteratorIterator($iter) as $file) { $files[] = $file->getPathname(); } return $files; } function explicitContent(array $words, array $files) { $intersect = array(); foreach($files as $path) { $file = file_get_contents($path); foreach($words as $word) { if (stripos($file, $word) !== false) { $intersect[$word][] = $path; } } } return $intersect; } $words = array( 'violence', 'terrorisme', '-18ans', ); $found = array(); if (isset($_POST['path'])) { $found = explicitContent($words, scanDirectory($_POST['path'])); } ?> <html> <body> <?php if ( ! isset($_POST['path'])):?> <form method="post" action="<?php echo rawurlencode($_SERVER['PHP_SELF'])?>"> <label for="txtpath">Veuillez entrer le nom du dossier :</label> <input id="txtpath" type="text" name="path" value="" /> <br /><br /> <input type="submit" name="bouton" value="Envoyer" /> </form> <?php else:?> <table border="1"> <thead> <tr> <th>Mot</th> <th>Trouvé dans</th> </tr> </thead> <tbody> <?php foreach($found as $word => $files):?> <tr> <td><?php echo htmlspecialchars($word, ENT_QUOTES)?></td> <td><?php echo htmlspecialchars(implode(' - ', $files), ENT_QUOTES)?></td> </tr> <?php endforeach?> </tbody> </table> <?php endif?> </body> </html>
Allez bon courage dans ton apprentissage.