Problem with line breaks in search engine

0

I'm developing a PHP search system without using a database and it works great except when there are line breaks. How can I solve this?

index.php

<form action="busca.php" method="get">
<input type="text" name="s"><br>
<input type="submit">
</form>

search.php

<?php
$pesq = (isset($_GET['s'])) ? trim($_GET['s']) : '';
if(empty($pesq)) {
echo 'Digite no campo de busca.';
}
else {
$index = "index.php";
$busca = glob("posts/conteudo/*.txt", GLOB_BRACE);
$lendo = "";
$conteudo = "";
foreach($busca as $item) {
if($item !== $index) {
$abrir = fopen($item, "r");
while(!feof($abrir)) {
$lendo = fgets($abrir);
$conteudo .= $lendo;
$lendo .= strip_tags($lendo);
}
if(stristr($lendo, $pesq) == true) {
$dados = str_replace(".txt", "", $item);
$dados = basename($dados);
$titulo = file_get_contents("posts/titulo/$dados.txt");
$result[] = "<a href=\"posts/postagem$dados.php\">$titulo</a>";
unset($dados);
}
fclose($abrir);    
}
}
if(isset($result) && count($result) > 0) {
$result = array_unique($result);
echo '<ul>';
foreach($result as $link) {
echo "<li>$link</li>";
}
echo '</ul>';
}
else {
echo 'Nenhum resultado na busca.<br /> Tente <b><label for="busca">pesquisar por palavras-chave diferentes</label></b> ou <b><label for="google">busque no Google</label></b>.
<br />
<form action="https://www.google.com.br/search" method="get" target="_blank">
<input type="search" name="q" placeholder="Busca no Google..." id="google" />
</form>';
}
}
?>

For example, if one of the files that search for the word "good" has the following excerpt "good morning", it works normally and the system can list the file. However, if I search for "good" in a file that has the "good morning" section (with a broken line between words), the system does not work and does not list the file.

    
asked by anonymous 22.01.2015 / 03:32

0 answers