How to choose the particular sentences in mysql in php?
$query = "select * from table where title LIKE '%{$java}%'";
if ($result = $mysqli->query($query))) {
$row = $result->fetch_array(MYSQLI_BOTH);
$title = $row2['title'];
if ($title ==TOBE== "<pink>$title</pink>") {
...........................
...........................
...........................
}
}
cause i want like this, I search the word "java", and when it appears, only the word java are pink
assuming $java
is a variable containing the search term
$query = "select * from table where title LIKE '%{$java}%'";
if ($result = $mysqli->query($query))) {
$row = $result->fetch_array(MYSQLI_BOTH);
$title = $row['title'];
$title = str_replace($java,"<pink>{$java}</pink>",$title);
}
this will replace any occurrence of the search term inside the string with the term wrapped in <pink>
so
"I don't like java programming"
will be
"I don't like <pink>java</pink> programming"
it will also work for this situation
"aldfhasdjavaasdkas;ldk"
will become
"aldfhasd<pink>java</pink>asdkas;ldk"
Use str_replace()
to substitute inside the title.
$query = "select * from table where title LIKE '%{$java}%'";
if ($result = $mysqli->query($query))) {
$row = $result->fetch_array(MYSQLI_BOTH);
$title = str_replace($java, "<pink>$java</pink>", $row['title']);
...
}