Salve allora ho risolto con uno script trovato qui si html.it:
<?php
// set text file location here
$PATH = 'pg19141.txt';
// if no location is set, an input field will be used (for a url)
#$PATH = null;
$search = filter_input(INPUT_GET,'q',FILTER_SANITIZE_STRING) ;
$source = filter_input(INPUT_GET,'loc',FILTER_SANITIZE_STRIN G);
//enforce url, no local paths
if (!empty($source)) $PATH = 'http://'.preg_replace('@^http://@','',$source);
$FILE = fopen($PATH,'r');
$results = '';
$line_number = 0;
$TEXT = '';
if ($FILE) {
while (!feof($FILE)) {
$buffer = fgetss($FILE, 4096);
++$line_number;
$TEXT .= "<div id=\"line_$line_number\">$buffer</div>";
$loc = preg_match('@('.preg_quote($search).')@i',$buffer) ;
if ($loc > 0) {
$results .= print_results($buffer,$search,$line_number,'line') ;
}
}
fclose($FILE);
}
// takes $line as input, outputs formatted search results for $str
function print_results($line,$str,$lnum=null,$class=null) {
$style = '';
if (null != $class) $style = " class=\"$class\"";
$res = "<div$style><span>$lnum</span>: ".preg_replace('@('.preg_quote($str).')@i',"<b >$1</b>",$line)."</div>";
return $res;
}
?>
<!doctype html>
<html>
<head>
<meta name="HandheldFriendly" content="true" />
<meta name="keywords" content="site search, search script, text index, remote search">
<meta name="description" content="Use this free PHP script to search text of files located on your web server or contents of remote web sites">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<table align="center"><td>
<script type="text/javascript">
$(document).ready(function() {
$('#results div').click(function() {
baseOffset = $('#context').offset().top;
baseOffset = $('#context').offsetTop;
targetLine = $(this).children().filter('span:first').text();
targetOffset = $('#line_'+targetLine).position().top;
$('#context').animate({scrollTop: $('#context').scrollTop() + targetOffset}, 400);
return false;
});
});
</script>
<style type="text/css">
.line {
background:#ccccff;
border:1px dotted #6666cc;
cursorointer;
}
.line span {
font-style:italic;
font-size:90%;
}
label:after {
content:': ';
}
.field label {
width:80px;
display:inline-block;
}
.field input {
width:200px;
}
#results,#context {
border:1px solid #ccc;
padding:3px;
min-width:300px;
width:45%;
float:left;
height:600px;
overflow:auto;
position:relative;
}
#output {
margin:19px auto;
width:90%;
position:relative;
}
#ad {
float:right;
}
</style>
</head>
<body>
<h1><?php echo $title; ?></h1>
<div align="center">
<form action="" method="GET">
<?php if (empty($PATH) || !empty($source)): ?>
<div class="field"><label for="source">Posizione</label><input type="text" name="loc" id="source" class="source" value="<?php echo $source; ?>"></div>
<?php endif; ?>
<div class="field"><label for="search">Cerca</label><input type="text" name="q" id="search" class="search" value="<?php echo $search; ?>"></div>
<br><input type="submit" value="Cerca"></div>
</form>
<br>
<?php if (!empty($search)) echo "<h2>Risultato $searched</h2>";?>
<?php echo $results;?></td></table>
</div>
</div>
</div>
</body>
</html>
funziona ma ora c'è un problema, ovvero aprendo la pgina con lo script mi mostra tutto il contenuto del file e poi se faccio la ricerca mi trova quello che deve trovare. Come posso non far vedere la lista totale?
Vorrei che venisse mostrato solo il risultato una volta cercato.
Grazie mille