Advertisement
Guest User

Untitled

a guest
Apr 29th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <html>
  2. <head>
  3.     <link rel="stylesheet" type="text/css" href="css.css" />
  4. </head>
  5. <body>
  6.     <form action="str.php" method="POST">
  7.         <ul>
  8.             <li><input type="text" name="keyword" placeholder="Jouw zoekterm" /></li>
  9.             <li><input type="submit" name="submit" value="Zoek" /></li>
  10.         </ul>
  11.     </form>
  12.     <br />
  13.     <br />
  14. </body>
  15. </html>
  16. <?php
  17. if(isset($_POST['submit']))
  18. {
  19.     $path = '../search';
  20.     $findThisString = $_POST['keyword'];
  21.     $dir = dir($path);
  22.  
  23. // Get next file/dir name in directory
  24.     if(empty($findThisString) == true)
  25.     {
  26.         echo "<hr>";
  27.         echo "Jouw zoekveld is leeg!! <br>";
  28.     }
  29.     else
  30.         {
  31.             {
  32.                 while (false !== ($file = $dir->read()))
  33.                     {  
  34.                         if ($file != '.' && $file != '..')
  35.                         {
  36.                             // Is this entry a file or directory?
  37.                             if (is_file($path . '/' . $file))
  38.                             {
  39.                                 // Its a file, yay! Lets get the file's contents
  40.                                 $data = file_get_contents($path . '/' . $file);
  41.  
  42.                                 // Is the str in the data (case-insensitive search)
  43.                                 if (stripos($data, $findThisString) !== false)
  44.                                 {
  45.                                     // sw00t! we have a match
  46.                                 echo "<div id='sfield'><h3>Zoekterm: ".$findThisString."</h3>";
  47.                                 echo "Gevonden in <a href='".$file."' target='new'>" . $file . "</a><br>\n</div>";
  48.                                 }
  49.                             }
  50.                         }
  51.                     }
  52.                         echo "<hr>";
  53.                         /*$filearr = array($fdata[] = 'filevalue');
  54.                         $fdata = file_get_contents($file);
  55.                         $pattern = preg_quote($findThisString, '/');
  56.                         $pattern = "/^.*$pattern.*\$/m";
  57.                         if(preg_match_all($pattern, $fdata, $matchs[] = 'filename'))
  58.                         {
  59.                             echo "Gevonden zoektermen <br>";
  60.                             echo implode("<br>", $matchs['filename']."<b>".$findThisString."<b><br>");
  61.                             echo "Gevonden zoeklinks: <a href='".$fdata."' target='new'>".$filearr['filevalue']."</a>";
  62.                         }
  63.                         else
  64.                         {
  65.                             echo "Geen match gevonden!!";
  66.                         }*/
  67.             }
  68.         }
  69. $lines = file($dir);
  70. $find = false;
  71. foreach($lines as $line)
  72. {
  73.     if(strpos($lines, $findThisString) !== false)
  74.     {
  75.         $find = true;
  76.         echo $line;
  77.     }
  78. }
  79. if(!$find)
  80. {
  81.     echo "Geen match gevonden!!";
  82. }
  83. closedir($dir); #This is meant to close the connection with the database!!     
  84. }
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement