Advertisement
Venciity

Sentence Extractor

Aug 21st, 2014
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Sentence Extractor</title>
  6. </head>
  7. <body>
  8.     <form action="" method="post">
  9.         <label for="input">Text : </label>
  10.         <br/>
  11.         <textarea name="inputText" id="input" cols="23" rows="10"></textarea>
  12.         <br/>
  13.         <label for="banList">word : </label>
  14.         <input type="text" name="word" id="word"/>
  15.         <br/>
  16.     </form>
  17.     <?php
  18.         if (isset($_POST['inputText']) && isset($_POST['word'])) {
  19.             $text = $_POST['inputText'];
  20.             $word = $_POST['word'];
  21.  
  22.             $sentence = "";
  23.             $WordsInSentence = [];
  24.  
  25.             for ($i = 0; $i < strlen($text); $i++) {
  26.                 if ($text[$i] == "." || $text[$i] == "?" || $text[$i] == "!") {
  27.                     $sentence .= $text[$i];
  28.                     $WordsInSentence = preg_split("/([^a-zA-Z])/", $sentence , -1 , PREG_SPLIT_NO_EMPTY);
  29.                     if (in_array($word ,$WordsInSentence)) {
  30.                         echo "$sentence </br>";
  31.                     }
  32.                     $sentence = "";
  33.                 }
  34.                 else {
  35.                     $sentence .= $text[$i];
  36.                 }
  37.             }
  38.         }
  39.     ?>
  40. </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement