RAYCHEV

pr6*-SentenceExtractor.php

Feb 5th, 2017
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $textInput = "This is my cat!Is this ! And this is my dog. We happily live in Paris – the most beautiful city in the world! Isn’t it great? Well it is :)    ";
  3. $word = "is";
  4.  
  5. $textArr = [];
  6. $sentence = "";
  7. for ($i = 0; $i <strlen($textInput); $i++){
  8.  
  9.     $ch = $textInput[$i];
  10.     $sentence .=$ch;
  11.     if ($ch == "." || $ch == "?" || $ch == "!"){
  12.         $textArr[] = $sentence;
  13.         $sentence = "";
  14.     }
  15. }
  16. //var_dump($sentence);
  17. foreach ($textArr as $snt){
  18.  
  19.     $sntArr = str_word_count($snt, 1);
  20.     $sntArr_len = count($sntArr);
  21.  
  22.     for ($ii = 0; $ii < $sntArr_len; $ii++){
  23.  
  24.         if ($sntArr[$ii] ==  $word){
  25.  
  26.             echo $snt . "\n";
  27.             break;
  28.         }
  29.     }
  30. }
  31.  
  32. ?>
RAW Paste Data