mmmm si ma non funge
volevo evitare ma sono costretto a postare tutto il codice..
in pratica sto facendo una pagina di ricerca fulltext e con 2 funzioni trovate qui nel forum evidenzio la parola cercata, infine con un while stampo i risultati...
Codice PHP:
<?php include ('common/db.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ricerca</title>
</head>
<body>
<?
function bolder($txt1,$htm,$words){
$txt1 = preg_replace("/$words/i",'[b]<font color=\'#CC0000\'>$0</font>[/b]', $txt1) ;
return $txt1.$htm;
}
function grassetto($stringa,$words){
return preg_replace('/([^<]*)(<(\w.*?|\/\w+)>)?/eis', 'bolder(\'$1\',"$2",\''.$words.'\')', $stringa);
}
?>
<form id="prova" action="test.php" method="post" enctype="multipart/form-data">
<input type="text" name="cerca" value="" />
<input type="submit" name="invia" value="Cerca" />
</form>
<?
$appendiurl = "http://xxxx.it/";
if(isset($_REQUEST['cerca']) && $_REQUEST['cerca']!=''){
$cerca = preg_replace ('/\x20+/','|', trim($_REQUEST['cerca']));
$qsearch = mysql_query("select * from sez_stat where lower(content) like lower('%$cerca%')") or die("Query fallita !".mysql_error());
while ($res = mysql_fetch_array($qsearch)) {
echo "<div style=\"border:1px solid silver;margin-top:10px;padding:5px;\">
";
echo "Sezione: ".$res['name']."
";
echo "<font size=\"-1\">";
$frase = grassetto($res['content'],$cerca);
$rex = '/(\w+\W+){1,10}'.$cerca.'(\W+\w+){1,10}/';
preg_match( $rex,$frase,$match );
echo "[...]".$match[0]."[...]" ;
echo "</font>
";
echo "<a href=\"".$res['file']."\">".$appendiurl.$res['file']."</a>";
echo "</p></div>";
}
}
?>
</body>
</html>