Поиск с подсветкой
<?php
header('Content-Type: text/html;charset=utf8');
$mysql=mysql_pconnect('localhost','root','');
mysql_select_db('tests',$mysql) or die(mysql_error());
mysql_query('set charset utf8') or die(mysql_error());
?>
<form method="post">
<input type="text" name="stext" <?php if($_POST){echo $_POST['stext'];} ?> />
<input type="submit" value="поиск" />
</form>
<style>
.slovo{
display: inline;
color: black;
background-color: #FC0;
border-radius: 4px;
padding: 3px;
}
</style>
<?php
if($_POST){
$stext=$_POST['stext'];
$sl = explode("",$stext);
$tosearch;
$all=count($s1)-1;
foreach($sl as $index=>$val) {
if($all!=$index){
$tosearch.="'text' LIKE '%$val%' OR";
} else {
$tosearch.="'text' LIKE '%$val%'";
}
}
$sql="SELECT * FROM 'search' WHERE (".$tosearch.")";
$q=mysql_query($sql) or die(mysql_error());
echo '<ol>';
while ($arr=mysql_fetch_array($q)) {
$text=$arr['text'];
foreach($s1 as $index=>$val) {
$text=str_replace($val, '<div class="slovo">'.$val.'</div>', $text);
}
echo '<li>'.$text.'</li>';
}
echo '</ol>';
}
mysql_close($mysql);
?>
Комментарии:
Нету комментариев для вывода...