<?php $a=0; $g=$_POST["search"]; $f = fopen("book.txt", "r"); $i=0; if (strlen($g)==0){ echo '<p>Clear</p>';}//если пустая форма else{ if (strlen($g) <3){ echo '<p>Short</p>';}//проверка на длину вбитых слов в поле поиска else { while(!feof($f)){ $str[$i]=fgets($f); echo $str[$i]."<br>"; $i=$i+1; } echo "<hr>"; echo "<br>"; function dropBackWords($g) { //тут мы обрабатываем одно слово $reg = "/(ay|oy|a|ii|ai)$/"; //данная регулярная функция будет искать совпадения окончаний $g = preg_replace($reg,'',$g); //убиваем окончания return $g; } $form=explode(" ",$g);//разбиение вбитого в форму $rez=array();//создание пустого массива $l=0;//индекс для логики switch( $_POST["and"] ) {case 'or': foreach ($form as $b){ $b=dropBackWords($b); foreach ($str as $x) { if (stristr($x,$b)==true) $rez[$l]=$x."<br>";$l=$l+1; } } break;} $result = array_unique($rez);//Убирает повторения foreach($result as $o){echo $o."<br>";} echo "<hr>"; } } fclose($f); ?> 
  • for the button "or" I wrote - Anton_14
  • @ Anton_14, Try to write more detailed questions. Explain what you see the problem, how to reproduce it, etc. - Nicolas Chabanovsky
  • I have 2 radio buttons in the search engines "and" and "or". for example, I enter the search field "computer science and mathematics" and select the "or" button. In my library there are books "computer science", but there are no books "mathematics". then he will give me all the buttons "informatics", as they are in my database of books, but "mathematics" is not. In this case, the match is either one or the other. When you click the radio button and my search engine should give all found books "computer science and mathematics." This is what I can't write. - Anton_14

0