I want to negate the searched terms in the results, but when I use explode
, and I try to use str_replace
, I get an array back.
<?php
$search_term = filter_var( $_GET['s'], FILTER_SANITIZE_STRING );
$palavras = explode( ' ', $search_term );
$q = 'SELECT * FROM classificados WHERE';
for ( $i = 0; $i < count($palavras); $i++ ) {
$q.= " texto LIKE '%" . $palavras[$i] . "%' AND " ;
}
$q.= " aprovado='s' ORDER BY ID desc";
$r = mysql_query( $q );
if ( mysql_num_rows( $r )==0) //no result found
{
echo "<div id='search-status'>Nenhum resultado encontrado!</div>";
}
else //result found
{
echo "<ul>";
while($row = mysql_fetch_assoc($r)) {
// aqui nao funciona
$title = str_replace($palavras, "<b>". $palavras[$i] ."</b>", $row['texto']);
?>
The search works, so if I look for "new bike", it returns the text, but the words do not appear as I want.