2
I want to blacken the terms searched in the results, but when I use the explode
, and I try to use in str_replace
, I get a 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, because if I search "new bike", returns the text, but the words are not displayed as I want.
Just for the record, mysql_* is (deprecated) from PHP 5.5, and functions will be removed in new versions of PHP.
– Diego Filipe Pedro Santos
and which command to replace?
– Arsom Nolasco
The alternatives aremysqli_ functions and PDO (PHP Data Objects). Some time ago you had a very interesting question and the answers were good. (http://answall.com/questions/579/por-que-n%C3%A3o-devo-usar-fun%C3%A7%C3%B5es-do-tipo-mysql)
– Diego Filipe Pedro Santos