0

Please help me , I want to do it with PHP,MySql
Suppose we have a sentence

"A grammatical unit that is syntactically independent and has a subject that is expressed"

I want to retrieve all data which matches with any consecutive five words in the above sentence, that is
"A grammatical unit that is" OR
"grammatical unit that is syntactically" OR
"unit that is syntactically independent" OR etc etc

Can we do with regex match or any easy solution?
Looking forward to you
Thanks

Ha Dev
  • 93
  • 1
  • 7

2 Answers2

0

You can put that conditions at database level, in mysql you can do this:

 select * from table_name where position('A grammatical unit that is' in field_name) > 0 or position('grammatical unit that is syntactically' in stradacstm) > 0 or position('unit that is syntactically independent' in stradacstm) > 0;
  • 1
    Thank you for this code snippet, which may provide some immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its educational value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Jul 17 '17 at 13:56
0

If you want to do it in PHP, you could try something like this:

  $sentence = "A grammatical unit that is syntactically independent and has a subject that is expressed";

$arr = explode(" ", $sentence);

var_dump($arr);
for ($i = 0; $i < (count($arr) - 5); $i++) {

      $newSentence = $arr[$i] + " " + $arr[$i + 1] + " " + $arr[$i + 2] + " " + $arr[$i + 3] + " " + $arr[$i + 4];
  //do database inset here

}
Lukas F.
  • 55
  • 8