Advertisement
AlexPolubiakin

php2ex10 script

Apr 8th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <meta charset="utf-8">
  2. <?php
  3. session_start();
  4.  
  5.     $dbserver   = "localhost";
  6.     $dbuser     = "root";
  7.     $dbpwd      = "";
  8.     $db         = "words";
  9.  
  10. $link = mysqli_connect($dbserver, $dbuser, $dbpwd, $db);
  11. if(mysqli_connect_errno() > 0){
  12.     echo mysqli_connect_error();
  13.     die;
  14. }
  15. mysqli_query($link,"SET NAMES UTF8");
  16.  
  17. $sql = "SELECT word,url FROM words";
  18. $result = mysqli_query($link,$sql);
  19. while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
  20.   {
  21.       $a[] = $row;
  22.   }
  23. $arr = explode( " ", $_POST['textarea'] );
  24.  
  25. foreach ($arr as $word){
  26.     foreach ($a as $key){
  27.         if($word == $key['word']){
  28.             $word = "<a href=" . $key['url'] . ">" . $key['word'] . "</a>";
  29.         }
  30.     }
  31.     $words[] = $word;
  32. }
  33.  
  34. $_SESSION['words'] = $words;
  35. header("Location: /");
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement